iOS 11,状态栏,导航栏和UIScrollview

E-M*_*add 3 ios swift3 snapkit ios11

我正在为iOS 11的应用程序进行一些更新,并遇到了一些我无法理解的问题.我的视图控制器以编程方式创建其所有子视图.

第一个孩子是Imageview.最重要的是,我添加了一个UIScrollView.在滚动视图中有一个UIView,在其中有一个标签.我通过代码使用SnapKit进行Autolayout约束.

iOS 9和iOS 10运行良好 - 没有问题.但是,在iOS 11中,它似乎工作正常,直到我"滚动"滚动视图.它没有像iOS 9和10那样弹回原来的位置,而是向下滚动,好像插图大约是实际的2倍.

它看起来像什么

// Scroll View
myScrollView = UIScrollView()
myScrollView.contentInset = UIEdgeInsetsMake(scrollInsetHeight(), 0, 0, 0)
myScrollView.backgroundColor = barBackgroundColor
myScrollView.isUserInteractionEnabled = true
self.view.addSubview(myScrollView)
myScrollView.snp.makeConstraints {
    make in
    make.edges.equalTo(self.view)
}

// Content View
contentView = UIView()
contentView.isUserInteractionEnabled = true
myScrollView.addSubview(contentView)
contentView.snp.makeConstraints {
    make in
    make.edges.equalTo(myScrollView)
    make.width.equalTo(self.view)
}

// Label
let lbl = UILabel()
lbl.text = "..."

lbl.font = UIFont(name: "OpenSans", size: 17)
lbl.textColor = .white
lbl.numberOfLines = 0

contentView.addSubview(lbl)
lbl.snp.makeConstraints {
    make in
    make.top.equalToSuperview().inset(20)
    make.left.right.equalToSuperview().inset(20)
}

// Resize Content
contentView.snp.makeConstraints {
    make in
    make.bottom.equalTo(lbl.snp.bottom).offset(20)
}
Run Code Online (Sandbox Code Playgroud)

E-M*_*add 14

使用新的UIScrollViewContentInsetAdjustmentBehavior进行非常简单的修复

if #available(iOS 11.0, *) {
    myScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.never
}
Run Code Online (Sandbox Code Playgroud)