美文网首页
UICollectionView的 header footer

UICollectionView的 header footer

作者: Peak_Liang | 来源:发表于2020-03-19 16:11 被阅读0次

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 直接添加了多个子控件,将不会出现悬停效果。

相关文章

网友评论

      本文标题:UICollectionView的 header footer

      本文链接:https://www.haomeiwen.com/subject/atelyhtx.html