简体   繁体   English

UIcollectionview装饰视图VS补充视图

[英]UIcollectionview decoration view VS supplementary view

I'm starting my development of an ios app using ios 6 and UICollectionView. 我正在使用ios 6和UICollectionView开始开发ios应用程序。 I've noticed there's support for both supplementary views and decoration views. 我注意到有补充观点和装饰观点的支持。

Can someone please explain in bullet points the difference between the two? 有人可以用子弹点解释两者之间的区别吗? They sound very similar. 它们听起来很相似。

If I want to add a loader to my collection view (that will appear at the bottom of each section, while the section is loading) should it be a supplementary view or a decoration view? 如果我想在我的集合视图中添加一个加载器(它将出现在每个部分的底部,而该部分正在加载)它应该是一个补充视图还是一个装饰视图?

Thanks 谢谢

Decoration views are just what the name says: decoration, chrome. 装饰视图正如名称所示:装饰,镀铬。 Only the collection view layout decides what they are and where to put them (for instance, if you want to draw lines on the screen every 5 items). 只有集合视图布局决定它们是什么以及放置它们的位置(例如,如果要在屏幕上每5个项目绘制一条线条)。

Supplementary views are more related to your data. 补充视图与您的数据更相关。 The collection view layout still decides where to put them, but they are provided by the collection view data source, just like regular cells. 集合视图布局仍然决定放置它们的位置,但它们由集合视图数据源提供,就像常规单元格一样。 For instance, if you wanted to put titles for sections, you would use supplementary views because the title would be different for each section and you need to call the data source for each. 例如,如果您想为部分添加标题,则可以使用补充视图,因为每个部分的标题都不同,您需要为每个部分调用数据源。

If your loader is generic, it could be a decoration view, however decorations views are not really accessible (the layout object says where to put them, and that is it, they are created by the collection view and you never get a reference to them), so if you want to start/stop animating it, a decoration view is not the best choice. 如果您的加载器是通用的,它可能是装饰视图,但装饰视图不是真正可访问的(布局对象说明放置它们的位置,就是它,它们是由集合视图创建的,您永远不会获得对它们的引用),所以如果你想开始/停止它的动画,装饰视图不是最好的选择。 If you use a supplementary view, then you have access to it at creation time (in your data source collectionView:viewForSupplementaryElementOfKind:atIndexPath: method). 如果使用补充视图,则可以在创建时访问它(在数据源collectionView:viewForSupplementaryElementOfKind:atIndexPath:方法中)。 However, you can only query the collection view for regular data cells once they are laid out on screen. 但是,只有在屏幕上布局常规数据单元格后,才能查询集合视图。 Also, you will have to write your own UICollectionViewLayout class if you want to use custom decoration or supplementary views. 此外,如果要使用自定义装饰或补充视图,则必须编写自己的UICollectionViewLayout类。 The base UICollectionViewFlowLayout only provides for a footer and a header supplementary view. 基本UICollectionViewFlowLayout仅提供页脚和标题补充视图。

from UITableView perspective : 从UITableView角度来看:

Supplementary = sections. 补充=部分。

Decoration = tableFooterView tableHeaderView Decoration = tableFooterView tableHeaderView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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