简体   繁体   English

UICollectionView粘性补充视图

[英]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: 一些信息:

  • I'm not using standard header/footers for flowLayout since it add a space between sections that I don't want 我没有为flowLayout使用标准的页眉/页脚,因为它在我不需要的部分之间添加了一个空格
  • Found this link which is pretty interesting from performance perspective but the example is somehow incomplete (great post though) 找到了这个链接 ,从性能的角度来看这是非常有趣的,但是示例还是不完整的(虽然很棒)
  • I'm trying to avoid 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM