美文网首页iOS 好文
iOS 11 tableView 20间距

iOS 11 tableView 20间距

作者: 随风踏叶 | 来源:发表于2017-06-19 17:21 被阅读668次

问题:iOS 11.0 tableView顶部出现20间距,如图:

我的解决方案:在基类控制器中重写viewWillAppear

-(void)viewWillAppear:(BOOL)animated{

[super viewWillAppear:animated];

//根据系统版本去掉自动调整

if ([UIDevice currentDevice].systemVersion.doubleValue >= 11.0) {

//遍历当前视图的subviews

for (id obj in CurControllerView.subviews) {

if ([obj isKindOfClass:[UITableView class]]) {

[obj setValue:@2 forKey:@"contentInsetAdjustmentBehavior"];

}

}

}else{

self.automaticallyAdjustsScrollViewInsets = NO;

}

}

原理

在iOS 11中automaticallyAdjustsScrollViewInsets废弃,改用scrollView的automaticallyAdjustsScrollViewInsets

相关文章

网友评论

    本文标题:iOS 11 tableView 20间距

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