I was making some updates to an app for iOS 11 and have run into something I cannot make sense of. My view controller creates all of its subviews programmatically.
The first child is an Imageview. On top of that I add a UIScrollView. Within the scroll view there is a UIView and within that a label. I'm using SnapKit for Autolayout constraints via code.
iOS 9 and iOS 10 work great - no issues. In iOS 11, however, it appears to work fine until I "pull down" on the scroll view. 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.
// 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
if #available(iOS 11.0, *) {
myScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.never
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With