iOS 9:UIScrollView再次被破坏了吗?

时间:2015-09-19 13:27:21

标签: ios uiscrollview ios9

我注意到UIScrollView可能再次被打破。我使用OS X 10.11.1Xcode 7 (from AppStore)Xcode 7.1 beta。 AutoLayout完成其工作后,contentOffset属性不在origin的{​​{1}}。

有人可以确认这个问题吗?

然而,我设法解决了问题,但这不是它应该如何:

UIScrollView

以下是重现此问题的方法:

override func viewDidLayoutSubviews() {

    super.viewDidLayoutSubviews()

    self.scrollView.contentOffset = CGPoint(x: 0, y: -self.scrollView.frame.origin.y)
    /* if you need a different position, I suggest to safe the 
       contentOffset inside viewWillLayoutSubviews and calculate the offset here */
} 

enter image description here

更新:报告并填充了雷达:22770934

UPDATE2:问题已解决。

1 个答案:

答案 0 :(得分:0)

我在视图调试器的帮助下找到了解决方案。

添加这些缺失的约束,一切都会好的:

self.containerView.topAnchor.constraintEqualToAnchor(self.scrollView.topAnchor).active = true
self.containerView.leftAnchor.constraintEqualToAnchor(self.scrollView.leftAnchor).active = true
self.containerView.rightAnchor.constraintEqualToAnchor(self.scrollView.rightAnchor).active = true
self.containerView.bottomAnchor.constraintEqualToAnchor(self.scrollView.bottomAnchor).active = true

// actually the debugger showed two different constraints, but this had no effect on the functionality, correct me here if I am wrong
// trailing and button constraints where like this:

// self.scrollView.trailingAnchor.constraintEqualToAnchor(self.containerView.trailingAnchor).active = true
// self.scrollView.bottomAnchor.constraintEqualToAnchor(self.containerView.bottomAnchor).active = true