[英]UICollectionView sticky supplementary view
Assuming I'm on a chat scenario, I want user images to move along with scroll until the other user's messages appear. 假设我处于聊天场景中,我希望用户图像随滚动一起移动,直到出现其他用户的消息。 Some visual example:
一些视觉示例:
I'm using a subclass of UICollectionViewFlowLayout
to display the messages and provide that initial left offset for the messages (the sectionInset
property is not working on iOS 9 for some reason) and I assumed handling a custom supplementary view to do what's shown above should not be that hard, but apparently it is :) 我正在使用
UICollectionViewFlowLayout
的子类来显示消息并提供消息的初始左偏移量( sectionInset
属性由于某些原因在iOS 9上不起作用),并且我假定要处理自定义补充视图以执行上面显示的操作很难,但显然是:)
Some info: 一些信息:
shouldInvalidateLayoutForBoundsChange:
to return true
and recreate attributes every time since chat cells can be complex in terms of size calculation. shouldInvalidateLayoutForBoundsChange:
每次返回true
并重新创建属性,因为聊天单元格在大小计算方面可能很复杂。 I believe this is not a weird scenario, have anyone accomplish something like this successfully? 我相信这不是一个奇怪的情况,有人成功完成了这样的事情吗? If so, I would appreciate some pointers.
如果是这样,我将不胜感激。
Thank you in advance. 先感谢您。
you can use sections for each cell groups. 您可以将节用于每个单元格组。 When using sections they have to be a clear background and be customized.
使用部分时,它们必须具有清楚的背景并进行自定义。 So message cells can be scrolled below sections and circle images on section will be on top of its cells.
因此,可以将消息单元格滚动到部分下方,而该部分上的圆圈图像将位于其单元格的顶部。
As a second way, you can use circle images apart from all collection items. 第二种方法是,除了所有收集项目之外,还可以使用圆形图像。 For this, you have to create circle images that how many required.
为此,您必须创建所需的圆形图像。 While scrolling up/down, they have to be moved as they will be anchored on top of message cells group.
向上/向下滚动时,必须将其移动,因为它们将锚定在消息单元组的顶部。
I hope it helps for you :) 希望对您有帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.