美文网首页
iOS 开发实战小知识(十)——UICollectionView

iOS 开发实战小知识(十)——UICollectionView

作者: Eddiegooo | 来源:发表于2018-07-07 11:02 被阅读38次

一:UICollectionView HeadView悬停效果

实现类似TableView 的 HeadView悬停效果
这个功能在iOS 9之前不太好实现,只能自定义UICollectionViewFlowLayout,自己计算滑动的高度距离来实现。 目前一般APP都支持iOS 9以上了,这里不多说了,自己去Google实现吧 O(∩_∩)O哈哈~

iOS 9之后, 系统有个属性, 直接设置实现悬停效果。

// 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 NS_AVAILABLE_IOS(9_0);
@property (nonatomic) BOOL sectionFootersPinToVisibleBounds NS_AVAILABLE_IOS(9_0);

只需将这两个属性设置为YES, 就能对应的实现,Header 或 FooterView 类似TableView的悬停效果。

二: 在iOS 11 系统之后,UICollectionView 的滚动条被SectionView 遮挡

问题图:


滚动条被sectionView 遮挡效果图.gif
解决办法:

在iOS 11 系统下, 定义一个类,继承CALayer, 将- (CGFloat)zPosition方法实现,设置为0. 在SectionView 里调用一下定义的这个类。

//定义一个类
#ifdef __IPHONE_11_0
@interface CustomLayerFixIOS11 : CALayer

@end
#endif

//实现对应的方法
#ifdef __IPHONE_11_0
@implementation CustomLayerFixIOS11

- (CGFloat)zPosition {
    return 0;
}

@end
#endif



//在SectionView里调用
#ifdef __IPHONE_11_0
+ (Class)layerClass {
    return [CustomLayerFixIOS11 class];
}
#endif

至此就能解决这个问题了。。

解决效果图:


解决效果图gif

相关文章

网友评论

      本文标题:iOS 开发实战小知识(十)——UICollectionView

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