android 滚动条被遮挡,iOS 11 下 UICollectionView 出现滚动条被 HeaderView 遮挡的问题

iOS 11 下 UICollectionView 出现滚动条被 HeaderView 遮挡的问题

在使用了- collectionView: viewForSupplementaryElementOfKind: atIndexPath:的 UICollectionView 页面中,滑动页面的时候滚动条会被 HeaderView 遮挡。导致滚动条看起来是断断续续的。

问题页面如下图所示(查看滚动条):

6989a7cd8891173fd1e0f5ae217ad677.png

以上问题具体是否与使用了 - collectionView: viewForSupplementaryElementOfKind: atIndexPath: 有关目前还不确定,待验证。

stackoverflow 中提供的是 swift 中的解决办法,我自己则使用的是 Objective-C。

提示:解决这个问题只是更改了继承自 UICollectionReusableView 的自定义 HeaderView 类文件,所以这里只贴该自定义 HeaderView 的代码。

先看看在修复问题之前的 CustomHeaderView 类文件代码

// CustomHeaderView.h

#import

extern NSString *const CustomHeaderViewReuseIdentifier;

@interface CustomHeaderView : UICollectionReusableView

@property (nonatomic, strong) UILabel *titleLabel;

@end

// CustomHeaderView.m

#import "CustomHeaderView.h"

NSString *const CustomHeaderViewReuseIdentifier = @"CustomHeaderView";

@implementation CustomHeaderView

- (void)layoutSubviews {

[super layoutSubviews];

[self createSubViews];

}

- (void)createSubViews {

_titleLabel = [[UILabel alloc] init];

_titleLabel.textColor = [UIColor blackColor];

CGFloat height = self.frame.size.height;

_titleLabel.frame = CGRectMake(15, 0, 100, height);

[self addSubview:_titleLabel];

}

@end

当为以上代码的时候,APP 在 iOS11 上运行就会出现上图的问题。

根据 stackoverflow 的提示更改代码之后,该问题便被修复。

以下为修复之后的CustomHeaderView类文件代码

// CustomHeaderView.h

#import

extern NSString *const CustomHeaderViewReuseIdentifier;

#ifdef __IPHONE_11_0

@interface CustomLayer : CALayer

@end

#endif

@interface CustomHeaderView : UICollectionReusableView

@property (nonatomic, strong) UILabel *titleLabel;

@end

// CustomHeaderView.m

#import "CustomHeaderView.h"

NSString *const CustomHeaderViewReuseIdentifier = @"CustomHeaderView";

#ifdef __IPHONE_11_0

@implementation CustomLayer

- (CGFloat) zPosition {

return 0;

}

@end

#endif

@implementation CustomHeaderView

- (void)layoutSubviews {

[super layoutSubviews];

[self createSubViews];

}

- (void)createSubViews {

_titleLabel = [[UILabel alloc] init];

_titleLabel.textColor = [UIColor blackColor];

CGFloat height = self.frame.size.height;

_titleLabel.frame = CGRectMake(15, 0, 100, height);

[self addSubview:_titleLabel];

}

#ifdef __IPHONE_11_0

+ (Class)layerClass {

return [CustomLayer class];

}

#endif

@end

以上代码相对于之前有问题的代码只是多了 #ifdef __IPHONE_11_0 ... #endif之间的内容,使用 #ifdef __IPHONE_11_0 ... #endif母的是防止更改之后的代码在 iOS 10 上出现问题,从而确保更改只是针对 iOS11 及之后的版本有效。

更改之后的效果图如下所示:

b9a60768a3ae2cdf9476b251230e4972.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值