![](/img/trans.png)
[英]Search Bar in a Navigation Item collapses and gets stuck under status bar upon navigation pop, on iOS 11
[英]iOS 11, Status bar, Navigation Bar and UIScrollview
我正在为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)
}
使用新的UIScrollViewContentInsetAdjustmentBehavior进行非常简单的修复
if #available(iOS 11.0, *) {
myScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.never
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.