contentInsetAdjustmentBehavior解析

2019-04-21  本文已影响0人  Silence_xl

UIViewController的automaticallyAdjustsScrollViewInsets属性被弃用了,系统推荐我们使用UIScrollView的contentInsetAdjustmentBehavior属性替代之。关于这个属性,系统提供了四种行为模式:

UIScrollViewContentInsetAdjustmentAutomatic
UIScrollViewContentInsetAdjustmentScrollableAxes
UIScrollViewContentInsetAdjustmentNever
UIScrollViewContentInsetAdjustmentAlways

contentInsetAdjustmentBehavior属性的这四个值:

1、首先是UIScrollViewContentInsetAdjustmentNever,如名所示:就算你的ScrollView超出了safeAreaInsets,系统不会对你的scrollView.adjustedContentInset做任何事情,即不作任何调整;
2、UIScrollViewContentInsetAdjustmentAlways: 只要超了安全区,就调整相应的超出值,调整的最大值不会超过安全区相应EdgeInsets方向的最大值,如刚刚上述第2点;
3、UIScrollViewContentInsetAdjustmentScrollableAxes:系统会根据ScrollView的滚动方向来进行判断,假设我只是一个横向滚动的ScrollView,那即便我的布局起点和高度值超过了self.view的安全区,那么系统也不会调整
4、scrollView.adjustedContentInset对应的top与bottom方向值,只可垂直方向滚动同理,直接设置scrollView.scrollEnabled = NO也同理;
UIScrollViewContentInsetAdjustmentAutomatic:系统默认值。文档上是这样说的:它与UIScrollViewContentInsetAdjustmentScrollableAxes行为相似,但是为了兼容以前①这种情况,即使scrollView是不可滚动,也会根据safeAreaInsets超出范围进行调整。

上一篇下一篇

猜你喜欢

热点阅读