美文网首页
iOS 11.0安全区域问题,并且指出属性到底属于哪个类

iOS 11.0安全区域问题,并且指出属性到底属于哪个类

作者: 三三哥 | 来源:发表于2017-10-17 17:04 被阅读0次

    11.0 scrollview 新增4个属性

    @property(nonatomic,readonly,strong) UILayoutGuide *contentLayoutGuide;

    @property(nonatomic,readonly,strong) UILayoutGuide *frameLayoutGuide;

    @property(nonatomic) UIScrollviewContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior;

    @property(nonatomic, readonly) UIEdgeInsets adjustedContentInset;

    粗体的2个属性是接下来要讲的,另外两个暂时没卵用!

    首先了解概念:安全区域safeAreaInsets

    根据官方文档大致翻译:

    The insets that you use to determine the safe area for this view.

    The safe area of a view reflects the area not covered by navigation bars, tab bars, toolbars, and other ancestors that obscure a view controller's view.(In tvOS, the safe area reflects the area not covered by the screen's bezel.) You obtain the safe area for a view by applying the insets in this property to the view's bounds rectangle. If the view is not currently installed in a view hierarchy, or is not yet visible onscreen, the edge insets in this property are0.

    For the view controller's root view, the insets account for the status bar, other visible bars, and any additional insets that you specified using theadditionalSafeAreaInsetsproperty of your view controller. For other views in the view hierarchy, the insets reflect only the portion of the view that is covered. For example, if a view is entirely within the safe area of its superview, the edge insets in this property are0.

    You might use this property at runtime to adjust the position of your view's content programmatically.

    安全区域就是不被导航栏、工具栏、或者另外一些复杂的控制器的view的父类(最后一句没理解),所覆盖。

    我们也可以去扩展安全区域,对于view 就设置safeAreaInsets,对于ViewController 可以设置additionalSafeAreaInsets(可以用于扩展VC的安全区域!)

    VC的安全区域属性additionalSafeAreaInsets

    类似View的safeAreaInsets

    重点:UIScrollView的安全区域:adjustedContentInset

    The insets derived from the content insets and the safe area of the scroll view.

    Use this property to obtain the adjusted area in which to draw content. The contentInsetAdjustmentBehavior property determines whether the safe area insets are included in the adjustment.The safe area insets are then added to the values in thecontentInsetproperty to obtain the final value of this property.

    加粗部分可以翻译成adjustedContentInset =safeAreaInsets + contentInset(偏移量,这个属性大家应该很熟悉)。,具体计算方式根据contentInsetAdjustmentBehavior来定

    contentInsetAdjustmentBehavior这个就是决定系统怎样计算UIScrollView的adjustedContentInset 值

    contentInsetAdjustmentBehavior枚举值的翻译

    UIScrollviewContentInsetAdjustmentAutomic 和UIScrollViewContentInsetAdjustmentScrollableAxes 类似 ,除了一点:如果UIScrollview 在automaticallyAdjustsScrollViewContentInset = YES 的ViewController上,adjustedContentInset =safeAreaInsets + contentInset。不管是否设置滚动

    UIScrollViewContentInsetAdjustmentScrollableAxes, 在滚动个方向上计算方式adjustedContentInset =safeAreaInsets + contentInset

    UIScrollViewContentInsetAdjustmentNever  不计算adjustedContentInset

    UIScrollViewContentInsetAdjustmentAlways     adjustedContentInset =safeAreaInsets

    补充automaticallyAdjustsScrollViewContentInset:

    A Boolean value that indicates whether the view controller should automatically adjust its scroll view insets.

    The default value of this property isYES, which lets container view controllers know that they should adjust the scroll view insets of this view controller’s viewto account for screen areas consumed by a status bar, search bar, navigation bar, toolbar, or tab bar. Set this property toNOif your view controller implementation manages its own scroll view inset adjustments.

    automaticallyAdjustsScrollViewContentInset = Yes ,系统自动计算VC内嵌的UIScrollView的偏移量(红色部分)

    差不多把关于偏移量的属性都翻译一遍了。如果认真从头到位看了,脑中应该会有一个联系起来的概念,之前网上看了一堆,大部分相同,但是看的时候很没有头绪,因为都没有指出一些属性到底属于哪个类,所以自己从头到尾把官方文档看了一下1

    相关文章

      网友评论

          本文标题:iOS 11.0安全区域问题,并且指出属性到底属于哪个类

          本文链接:https://www.haomeiwen.com/subject/qowduxtx.html