简体   繁体   English

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

[英]iOS 11, Status bar, Navigation Bar and UIScrollview

I was making some updates to an app for iOS 11 and have run into something I cannot make sense of. 我正在为iOS 11的应用程序进行一些更新,并遇到了一些我无法理解的问题。 My view controller creates all of its subviews programmatically. 我的视图控制器以编程方式创建其所有子视图。

The first child is an Imageview. 第一个孩子是Imageview。 On top of that I add a UIScrollView. 最重要的是,我添加了一个UIScrollView。 Within the scroll view there is a UIView and within that a label. 在滚动视图中有一个UIView,在其中有一个标签。 I'm using SnapKit for Autolayout constraints via code. 我通过代码使用SnapKit进行Autolayout约束。

iOS 9 and iOS 10 work great - no issues. iOS 9和iOS 10运行良好 - 没有问题。 In iOS 11, however, it appears to work fine until I "pull down" on the scroll view. 但是,在iOS 11中,它似乎工作正常,直到我“滚动”滚动视图。 Instead of bouncing back to its original position as iOS 9 and 10 do, it stays scrolled down as if the insets were about 2x what they actually are. 它没有像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)
}

Pretty simple fix using the new UIScrollViewContentInsetAdjustmentBehavior 使用新的UIScrollViewContentInsetAdjustmentBehavior进行非常简单的修复

if #available(iOS 11.0, *) {
    myScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.never
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM