UIScrollView

2020-07-17  本文已影响0人  bianruifeng

在某些情况下(navigationBar透明的时候),系统底层对UIScrollView及基于UIScrollView 的控件 初始位置 做了偏移;

解决方案:

  1. 设置ScrollView不自动
[self setAutomaticallyAdjustsScrollViewInsets:NO]
//self.automaticallyAdjustsScrollViewInsets = NO;//同上


/*iOS11: 
在iOS11中`UIViewController`的`automaticallyAdjustsScrollViewInsets`属性被废弃,不再起作用, 
取而代之的是`UIScrollView`中新增的属性`contentInsetAdjustmentBehavior`
*/
//`UITextView`继承自`UIScrollView`,所以也是设置`contentInsetAdjustmentBehavior`
//效果同iOS11前的`self.automaticallyAdjustsScrollViewInsets = NO;`

scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1. 设置导航不透明
self.navigationController.navigationBar.translucent = NO;
  1. 边界延伸设置为None
self.edgesForExtendedLayout = UIRectEdgeNone;  
//默认为UIRectEdgeAll,会向上下左右偏移,偏移到(0,0)
//setf.extendedLayoutIncludesOpaqueBars = NO;
//这里系统默认就是NO,如果单设EdgesForExtendedLayout无效可以试试加上这句

UIScrollView+九宫格

上一篇 下一篇

猜你喜欢

热点阅读