美文网首页
iOS11的automaticallyAdjustsScroll

iOS11的automaticallyAdjustsScroll

作者: 面糊 | 来源:发表于2017-09-29 11:40 被阅读44次

    @available(iOS, introduced: 7.0, deprecated: 11.0)
    open var automaticallyAdjustsScrollViewInsets: Bool // Defaults to YES

    此方法在iOS 11后被弃用, 取而代之的新属性为:

    /* Configure the behavior of adjustedContentInset.
     Default is UIScrollViewContentInsetAdjustmentAutomatic.
     */
    @available(iOS 11.0, *)
    open var contentInsetAdjustmentBehavior: UIScrollViewContentInsetAdjustmentBehavior
    

    UIScrollViewContentInsetAdjustmentBehavior是一个新的枚举, 由于iPhoneX的存在, 为了适配齐刘海儿safe area而新增的属性, 专门用于ScrollView自动调整contentInset. 具体的枚举成员如下:

    public enum UIScrollViewContentInsetAdjustmentBehavior : Int {
    
    case automatic // Similar to .scrollableAxes, but for backward compatibility will also adjust the top & bottom contentInset when the scroll view is owned by a view controller with automaticallyAdjustsScrollViewInsets = YES inside a navigation controller, regardless of whether the scroll view is scrollable
    
    case scrollableAxes // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES)
    
    case never // contentInset is not adjusted
    
    case always // contentInset is always adjusted by the scroll view's safeAreaInsets
    }
    

    解决问题:

    if #available(iOS 11.0, *) {
            tableView.contentInsetAdjustmentBehavior = .automatic
        } else {
            automaticallyAdjustsScrollViewInsets = false
        }

    相关文章

      网友评论

          本文标题:iOS11的automaticallyAdjustsScroll

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