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

问题描述:

我对iOS 11的应用程序进行了一些更新,并遇到了一些我无法理解的内容。我的视图控制器以编程方式创建其所有子视图。iOS 11,状态栏,导航栏和UIScrollview

第一个孩子是一个Imageview。最重要的是,我添加了一个UIScrollView。在滚动视图内有一个UIView,并在其中有一个标签。我通过代码使用SnapKit进行Autolayout约束。

iOS 9和iOS 10工作良好 - 没有问题。但是,在iOS 11中,出现才能正常工作,直到我“滚动”滚动视图。不像iOS 9和10那样反弹回原来的位置,它保持向下滚动,就好像插入物大约是它们实际的2倍。

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) 
} 

使用新UIScrollViewContentInsetAdjustmentBehavior

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

很简单修复,谢谢!像魅力一样工作。 –

+1

你救了我的一天!=) – user2154220