在 UICollectionViewFlowLayout 使其布局无效后重绘单元格 [英] Redraw cells after UICollectionViewFlowLayout invalidates its layout

查看:31
本文介绍了在 UICollectionViewFlowLayout 使其布局无效后重绘单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您使 UICollectionViewFlowLayout 上的布局无效时,它会为您的每个单元格创建一堆新的布局属性;但是,它不会告诉您的单元格重新绘制,这会导致任何图层绘图中的扭曲.

When you invalidate layout on a UICollectionViewFlowLayout it creates a bunch of new layout attributes for each of your cells; it doesn't tell your cells to redraw however, which causes distortions in any Layer drawings.

我不想告诉我的集合重新加载它的数据,因为这会删除你在流属性之间的任何好的过渡:例如,我有一个网格布局过渡到一个覆盖流.

I don't want to tell my collection to reload its data because this removes any nice transitions you have between flow attributes : I have a grid layout transitioning into a coverflow for example.

我需要一种方法让 UICollectionViewController 类告诉单元格在获得布局属性后调用它们的 [setNeedsDisplay] 方法.

I need a way for the UICollectionViewController class to tell the cells to call their [setNeedsDisplay] method after being given the layout attributes.

推荐答案

当您的单元格改变大小时,由他们来处理(拉伸与重绘).这是由 UIView contentMode 属性控制的;尝试将其设置为 UIViewContentModeRedraw 以导致调整大小使您的视图内容无效,例如 setNeedsDisplay: 会.

When your cells change size, it's up to them how to handle that (stretching vs redrawing). This is controlled by the UIView contentMode property; try setting it to UIViewContentModeRedraw to cause resizing to invalidate your views contents like setNeedsDisplay: would.

如果您直接使用 CALayer 作为单元格的子层,您可以将它们的 needsDisplayOnBoundsChange 设置为 YES 以获得相同的效果.

If you're using CALayers directly as sub-layers of your cell, you can set their needsDisplayOnBoundsChange to YES in order to get the same effect.

这篇关于在 UICollectionViewFlowLayout 使其布局无效后重绘单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆