在某些情况下(navigationBar透明的时候),系统底层对UIScrollView及基于UIScrollView 的控件 初始位置 做了偏移;
解决方案:
- 设置ScrollView不自动
[self setAutomaticallyAdjustsScrollViewInsets:NO]
//self.automaticallyAdjustsScrollViewInsets = NO;//同上
/*iOS11:
在iOS11中`UIViewController`的`automaticallyAdjustsScrollViewInsets`属性被废弃,不再起作用,
取而代之的是`UIScrollView`中新增的属性`contentInsetAdjustmentBehavior`
*/
//`UITextView`继承自`UIScrollView`,所以也是设置`contentInsetAdjustmentBehavior`
//效果同iOS11前的`self.automaticallyAdjustsScrollViewInsets = NO;`
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- 设置导航不透明
self.navigationController.navigationBar.translucent = NO;
- 边界延伸设置为
None
self.edgesForExtendedLayout = UIRectEdgeNone;
//默认为UIRectEdgeAll,会向上下左右偏移,偏移到(0,0)
//setf.extendedLayoutIncludesOpaqueBars = NO;
//这里系统默认就是NO,如果单设EdgesForExtendedLayout无效可以试试加上这句
网友评论