1.tableView 的上移问题
在项目中使用了navigationController后,界面中有 tableView 或者 UIScrollView 的时候,在设置 frame 的时候,UITableView 的 frame 是从0开始的,在界面展示出来的时候,tableView 莫名的上移了64。解决方法:
self.edgesForExtendedLayout = UIRectEdgeNone;
2.去掉导航栏的分割线导致 tableView 上移
我们都知道如何除掉导航栏的那条分割线
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
使用了这两句话也有可能导致你的 tableView 上移。
-
当navigationBar.isTranslucent = true 的时候,你可以看到 TableView 是从 View 的原点(0,0)开始的,这个时候 navigationBar 是透明的
self.navigationController?.navigationBar.isTranslucent = true
-
当navigationBar.isTranslucent = false 的时候 ,可以很明显的看到 TabelView的布局是在 navgationBar 的下面,尽管tableView 的 frame 是从(0,0)开始写的
self.navigationController?.navigationBar.isTranslucent = false
3.NavigationBar 的左右按钮不能尽可能的靠近右边的话,可以设置下按钮的偏移量
button.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
4.关于 iOS11下,tableView 的向下偏移和 Seaction,Footer 变宽的问题
由于 TableView 默认开启了Self-Sizing,如果你没有设置 estimatedRowHeight 的话,会变得很奇怪。所以需要这样
if (@available(iOS 11.0, *)){
self.estimatedRowHeight = 0;
self.estimatedSectionHeaderHeight = 0;
self.estimatedSectionFooterHeight = 0;
}
5. UIScrollViewContentInsetAdjustmentBehavior的问题
如果你的项目中之前因为有 TableView 或者 ScrollView 和 navigationBar 导致位置偏移而使用了
automaticallyAdjustsScrollViewInsets=NO;
因为在 iOS11中废弃了,所以你需要使用
contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
网友评论