我正在对适用于 iOS 11 的应用进行一些更新,遇到了一些我无法理解的问题。我的 View Controller 以编程方式创建它的所有 subview 。
第一个 child 是 Imageview。最重要的是我添加了一个 UIScrollView。在 ScrollView 中有一个 UIView 和一个标签。我正在通过代码使用 SnapKit 进行自动布局约束。
iOS 9 和 iOS 10 运行良好 - 没有问题。然而,在 iOS 11 中,它似乎可以正常工作,直到我“下拉” ScrollView 。它不会像 iOS 9 和 10 那样弹回到原来的位置,而是保持向下滚动,就好像插图大约是实际位置的两倍。
// 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)
}
最佳答案
使用新的 UIScrollViewContentInsetAdjustmentBehavior 进行非常简单的修复
if #available(iOS 11.0, *) {
myScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.never
}
关于iOS 11、状态栏、导航栏和 UIScrollview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46249859/