iOS11适配tableview

1 tableview出现的问题,可以改所有的tableview继承于一个自定义的tableview,在里面适配iOS11.


@interface GWParentTableView : UITableView

@end

@implementation GWParentTableView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
         [self adapt];
    }
    return self;
}
- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    if (self = [super initWithFrame:frame style:style]) {
        [self adapt];
    }
    return self;
}
//适配
- (void)adapt{
    [self adaptRefresh];
    [self adaptPageOffset];
}
//滚动条高度跳动、上下拉刷新问题
- (void)adaptRefresh
{
    self.estimatedRowHeight = 0;
    self.estimatedSectionHeaderHeight = 0;
    self.estimatedSectionFooterHeight = 0;
}
//列表/页面偏移
- (void)adaptPageOffset
{
    if (@available(iOS 11.0, *)){
        self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
}

@end

2 scrollview,tabelview都会出现页面偏移问题,可以在appdelegate里面统计设置。


- (void)adaptPageOffset
{
    if (@available(iOS 11.0, *)){
        self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
}



你可能感兴趣的:(iOS适配)