在开发中遇到这样一个问题 就是在scrollview里的东西使劲往下拉 然后会掉下去大概一个导航条的高度。
而且在scrollview左右拖动的时候还会出现上下漂移的情况。
解决这种情况可以设置
self.automaticallyAdjustsScrollViewInsets = NO;//默认是YES
看一下官方文档:
automaticallyAdjustsScrollViewInsets
Specifies whether or not the view controller should automatically adjust its scroll view insets.
@property(nonatomic, assign) BOOL automaticallyAdjustsScrollViewInsets
Discussion
Default value is YES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set toNO if you want to manage scroll view inset adjustments yourself,
such as when there is more than one scroll view in the view hierarchy.
Availability
Available in iOS 7.0 and later.
Declared In
UIViewController.h
这个属性默认是YES,就是控制器允许根据 navigation bar toolbar tabor 等工具条占用的高度来调整scrollview的inset(词典翻译为插图个人理解问scrollview的内部插入的view等子视图与scrollview的内部容器的关系),如果你想自己管理scrollview的容器与子控件的关系那么你可以设置成NO,在什么情况下要自己管理呢,就是在view层级内出现不止一个scrollView(个人理解为嵌套的scrollview)
至此文档说的很清楚了,要设置成NO的情况其实很明显了,就是在scrollview里面添加了scrollview,并且控制器中还有导航条及工具条的等控件。tableview,collectionview都是继承自scrollview的 所以在scrollview中添加tableview或者collectionview应该也会出现这种情况,而这时设置成NO就好了。
另外当视图第一个添加scrollview的时候也会调整,所以一般先创建个UIView再把scrollview放进去会好点,不然可能出现小屏幕适配的时候最下面拉不上去能拉着看见但是松手就会弹回去。
所以控制器针对scrollview的自动调整要注意,总结下 两种情况设置成NO 1.scrollview嵌套ScrollView(tableview collectionview也是继承自scrollview)
2.创建视图直接先创建scrollview。
手打如有打字错误请见谅。