iOS小技巧-多个UIListView设置automaticallyAdjustsScrollViewInsets属性

开发中如果在同一个viewcontroller中,同时出现两个以上的UIListView时,如果包含多个UIListView,设置他们的frame一样,会出现:有一个UIListView是正常的,其他的位置都会偏移到顶部上去,譬如所有的UIListView的frame都设置为(0,0,320,568)的时候,只有一个UIListView的y=0值是在从导航栏底部开始计算,其他的y=0都是从屏幕的最顶部开始计算。要想所有的UIListView的起始位置一致,其他的UIListView的frame必须设置为(0,64,320,568-64),为何?

其实,这是因为iOS7(含)以后,有一个automaticallyAdjustsScrollViewInsets属性引起的,此属性的默认值为YES。

官方文档解释如下:
 
A Boolean value that indicates whether the view controller should automatically adjust its scroll view insets.
 
Declaration
SWIFT
var automaticallyAdjustsScrollViewInsets: Bool
OBJECTIVE-C
@property(nonatomic, assign) BOOL automaticallyAdjustsScrollViewInsets
Discussion
The default value of this property 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 to NO 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.

简单理解为:automaticallyAdjustsScrollViewInsets是否根据view controller所在界面的status bar,navigation bar,toolbar或者tabbar的高度,自动调整scrollview的 inset。默认为YES自动调整,如果设置为NO,不让view controller自动调整。
所以,只要设置一下view controller的automaticallyAdjustsScrollViewInsets属性为NO,问题就解决了!
self.automaticallyAdjustsScrollViewInsets = NO;





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值