Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

What it looks like

// 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)
}
like image 741
E-Madd Avatar asked Dec 01 '22 11:12

E-Madd


1 Answers

Pretty simple fix using the new UIScrollViewContentInsetAdjustmentBehavior

if #available(iOS 11.0, *) {
    myScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.never
}
like image 113
E-Madd Avatar answered Dec 05 '22 08:12

E-Madd