2017-09-16 198 views
3

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

回答

9

使用新UIScrollViewContentInsetAdjustmentBehavior

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

很簡單修復,謝謝!像魅力一樣工作。 –

+1

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