UICollectionView的 header footer 悬停效果

iOS 9.0 之后,官方提供了两个属性,支持 UICollectionViewheaderfooter 悬停效果。

// Set these properties to YES to get headers that pin to the top of the screen and footers that pin to the bottom while scrolling (similar to UITableView).
@property (nonatomic) BOOL sectionHeadersPinToVisibleBounds API_AVAILABLE(ios(9.0));
@property (nonatomic) BOOL sectionFootersPinToVisibleBounds API_AVAILABLE(ios(9.0));

字面意思写的非常清楚,而这两个属性属于 UICollectionViewFlowLayout ,所以使用方法也很明显。

        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.sectionHeadersPinToVisibleBounds = YES;
        layout.sectionFootersPinToVisibleBounds=YES;

这里需要注意的是,UICollectionViewheader 是由 UICollectionReusableView 创建的。请确保 reusableView 只有一个直接子控件,如果 reusableView 直接添加了多个子控件,将不会出现悬停效果。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容