理解几个影响布局的属性

2018-08-22  本文已影响0人  GTMYang

1. edgesForExtendedLayout

@available(iOS 7.0, *)
open var edgesForExtendedLayout: UIRectEdge

控制Controller的view是否扩展到半透明的bar(NavigationBar, UITabBar)所在的区域

// top, left, bottom, right, all
edgesForExtendedLayout = []  // 四个方向都不伸展

@available(iOS 7.0, *)
public struct UIRectEdge : OptionSet {
    public init(rawValue: UInt)
    public static var top: UIRectEdge { get }
    public static var left: UIRectEdge { get }
    public static var bottom: UIRectEdge { get }
    public static var right: UIRectEdge { get }
    public static var all: UIRectEdge { get }
}

2. automaticallyAdjustsScrollViewInsets

    @available(iOS, introduced: 7.0, deprecated: 11.0, message: "Use UIScrollView's contentInsetAdjustmentBehavior instead")
    open var automaticallyAdjustsScrollViewInsets: Bool // Defaults to YES

值为YES的时候自动调整UIScrollView的contentInset值来保证内容不被bar(NavigationBar, UITabBar)遮挡,iOS11中用contentInsetAdjustmentBehavior替代该属性。


        if #available(iOS 11, *) {
            wkWebView?.scrollView.contentInsetAdjustmentBehavior = .never // 不自动调整 ContentInset
        } else {
            automaticallyAdjustsScrollViewInsets = false  // 不自动调整 ContentInset
        }

3. contentInset

ScrollView的边距控制属性

参考文章

上一篇 下一篇

猜你喜欢

热点阅读