iOS 知识点iOS 点滴锻炼吃饭的家伙

adjustedContentInset | safeAreaI

2018-02-25  本文已影响12人  面皮大师

iOS 11中Controller的automaticallyAdjustsScrollViewInsets属性被废弃了.
替代的是上文说的UIScrollerView中的contentInsetAdjustmentBehavior.
这个属性是枚举类型:

typedef NS_ENUM(NSInteger, UIScrollViewContentInsetAdjustmentBehavior) {
        UIScrollViewContentInsetAdjustmentAutomatic, 
        UIScrollViewContentInsetAdjustmentScrollableAxes, 
        UIScrollViewContentInsetAdjustmentNever, 
        UIScrollViewContentInsetAdjustmentAlways,
    } API_AVAILABLE(ios(11.0),tvos(11.0));

如何理解这几个枚举类型的区别和意思需要先弄明白下面几个属性.

safeAreaInset

先说一下什么是安全区域,安全区域帮助我们将view放置在整个屏幕的可视的部分。即使把navigationbar设置为透明的,系统也认为安全区域是从navigationbar的bottom开始,保证不被系统的状态栏、或导航栏覆盖。

safeAreaInsets属性反映了一个view距离该view的安全区域的边距。换一句更容易理解的是:去掉StatusBar、NavigationBar、TabBar等视图,距离屏幕上下左右的距离. safeAreaInsets并不是一个需要设置的属性,系统会根据各种Bar的情况自己计算(包括在iphoneX上下的距离计算).

contentInset

contentInset在上一篇文章中介绍过了,表示一个ScrollerView的内容周围增加的边距,这个系统默认是0,需要手动的去调整设置.

adjustedContentInset

自适应内容边距, contentInsetAdjustmentBehavior的各种值设置的就是这个属性.

1.UIScrollViewContentInsetAdjustmentAutomatic:
如果scrollview在一个automaticallyAdjustsScrollViewContentInset = YES的controller上,并且这个Controller包含在一个navigationController中,这种情况下会设置在top & bottom上 adjustedContentInset = safeAreaInset + contentInset(不管是否滚动)。其他情况下与UIScrollViewContentInsetAdjustmentScrollableAxes相同.

2.UIScrollViewContentInsetAdjustmentScrollableAxes:
在可滚动方向上adjustedContentInset = safeAreaInset + contentInset,在不可滚动方向上adjustedContentInset = contentInset;依赖于scrollEnabled和alwaysBounceHorizontal / vertical = YES,scrollEnabled默认为yes,所以大多数情况下,计算方式还是adjustedContentInset = safeAreaInset + contentInset.

3.UIScrollViewContentInsetAdjustmentNever:
adjustedContentInset = contentInset

4.UIScrollViewContentInsetAdjustmentAlways:
adjustedContentInset = safeAreaInset + contentInset

addtionalSafeAreaInset

通过此设置可以修改safeAreaInset,进而影响内容视图的位置.

上一篇下一篇

猜你喜欢

热点阅读