如何像UITableView的tableHeaderView一样在UICollectionView中添加HeaderView [英] How to add HeaderView in UICollectionView like UITableView's tableHeaderView

查看:112
本文介绍了如何像UITableView的tableHeaderView一样在UICollectionView中添加HeaderView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 UICollectionView



的顶部添加标题视图/顶视图它应该像 UITableView tableHeaderView 属性一样执行。



因此,它需要位于第一部分标题视图的顶部(位于索引0的部分之前),与其他内容一起滚动并进行用户交互。



到目前为止我所得到的最好结果是创建一个特殊的XIB(带有 MyCollectionReusableView UICollectionReusableView 的子类c $ c>作为文件所有者)的第一部分标题视图,它的大小足以在标题中包含我的子视图,我认为这是一种黑客行为,而且我还没有设法检测到触摸。



不确定是否可以让我的 MyCollectionReusableView 子类允许接触或者有更好的方法。

解决方案

我已将视图置于集合的顶部通过添加一个UIView作为集合视图的子视图。它向上滚动集合视图,它具有普通的UIView用户交互。如果您没有部分标题,这可以正常工作,但如果您没有部分标题,则不起作用。在这种情况下,我看不出你做这件事的方式有什么问题。我不知道为什么你没有检测到触摸,他们为我工作得很好。


How can I add a header view / top view (not section header) at the top of a UICollectionView?

It should act excactly as UITableView's tableHeaderView property.

So it needs to sit on top of the first section header view (before the section at index 0), scroll along with the rest of the content, and have user interaction.

The best I've come up with so far is to make a special XIB (with MyCollectionReusableView subclass of UICollectionReusableView as the File's owner) for the first section header view that is big enough to also contain my subviews in header, it's kind of a hack, I think, and I haven't managed to detect touches.

Not sure if I can make my MyCollectionReusableView subclass to allow touches or there's a better way.

解决方案

I've put a view at the top of a collection view by just adding a UIView as a subview of the collection view. It does scroll up with the collection view and it has normal UIView user interaction. This works ok if you have no section header, but doesn't work if you do. In that situation, I don't see anything wrong with the way you're doing it. I'm not sure why you're not detecting touches, they work fine for me.

这篇关于如何像UITableView的tableHeaderView一样在UICollectionView中添加HeaderView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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