iOS 11 下 UICollectionView 的HeaderView 遮擋滾動條

這個問題在之前的 iOS 10 上是沒有的,iOS 11 新出之后才出現。在使用了- collectionView: viewForSupplementaryElementOfKind: atIndexPath:的 UICollectionView 頁面中,滑動頁面的時候滾動條會被 HeaderView 遮擋.

修改前的樣子:

//
//  CustomCollectionReusableView.m
//  EMall
//
//  Created by YJHou on 2017/9/16.
//  Copyright ? 2017年 stackhou . All rights reserved.
//

#import "CustomCollectionReusableView.h"

@interface CustomCollectionReusableView ()

@property (nonatomic, strong) UILabel *showLabel; /**< 顯示控件 */

@end

@implementation CustomCollectionReusableView

- (void)layoutSubviews {
    [super layoutSubviews];
    [self _setUpSubViews];
}

- (void)_setUpSubViews {
    [self addSubview:self.showLabel];
}

#pragma mark - Lazy
- (UILabel *)showLabel{    
    if (!_showLabel) {
        _showLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 120, self.frame.size.height)];
        _showLabel.font = [UIFont systemFontOfSize:13];
        _showLabel.textAlignment = NSTextAlignmentLeft;
        _showLabel.backgroundColor = [UIColor clearColor];
        _showLabel.textColor = [UIColor redColor];
    }
    return _showLabel;
}

@end

修復完成后

//
//  CustomCollectionReusableView.m
//  EMall
//
//  Created by YJHou on 2017/9/16.
//  Copyright ? 2017年 stackhou . All rights reserved.
//

#import "CustomCollectionReusableView.h"

#ifdef __IPHONE_11_0
@interface CustomLayer : CALayer

@end
#endif

@interface CustomCollectionReusableView ()

@property (nonatomic, strong) UILabel *showLabel; /**< 顯示控件 */

@end

#ifdef __IPHONE_11_0
@implementation CustomLayer

- (CGFloat) zPosition {
    return 0;
}

@end
#endif

@implementation CustomCollectionReusableView

- (void)layoutSubviews {
    [super layoutSubviews];
    [self _setUpSubViews];
}

- (void)_setUpSubViews {
    [self addSubview:self.showLabel];
}

#pragma mark - Lazy
- (UILabel *)showLabel{    
    if (!_showLabel) {
        _showLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 120, self.frame.size.height)];
        _showLabel.font = [UIFont systemFontOfSize:13];
        _showLabel.textAlignment = NSTextAlignmentLeft;
        _showLabel.backgroundColor = [UIColor clearColor];
        _showLabel.textColor = [UIColor redColor];
    }
    return _showLabel;
}

#ifdef __IPHONE_11_0
+ (Class)layerClass {
    return [CustomLayer class];
}
#endif

@end
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容