UICollectionView HeadView 问题

一: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 遮挡

问题图:

解决办法:

在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
复制代码

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

解决效果图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值