【发布时间】:2015-04-21 13:24:46
【问题描述】:
我有这个 ViewController :
主视图
_-滚动
__- 内容视图
我需要动态调整内容视图的大小
我有这个方法resizeScrollView(),这是我的方法:
private func resizeScrollView(){
self.mViewContainer.frame.size.height = 800
self.mScrollView.contentSize = self.mViewContainer.frame.size
NSLog("Scroll Height : " + NSNumber(float: Float(self.mScrollView.contentSize.height)).stringValue)
NSLog("Container Height : " + NSNumber(float: Float(self.mViewContainer.frame.height)).stringValue)
}
我有这些日志:
2015-04-21 15:11:44.854 quotle[3673:60b] Scroll Height : 800
2015-04-21 15:11:44.856 quotle[3673:60b] Container Height : 800
在这一步,两个视图都已正确调整大小。
在我的滚动事件中,我链接了这个方法:
func scrollViewDidScroll(scrollView: UIScrollView) {
NSLog("Scroll Height : " + NSNumber(float: Float(self.mScrollView.contentSize.height)).stringValue)
NSLog("Container Height : " + NSNumber(float: Float(self.mViewContainer.frame.height)).stringValue)
}
当我滚动时,我会看到这些日志:
2015-04-21 15:11:43.556 quotle[3673:60b] Scroll Height : 800
2015-04-21 15:11:43.559 quotle[3673:60b] Container Height : 416
所以,当我开始滚动时,我的内容视图会调整大小...
我的问题是:我必须做些什么才能在滚动时将内容视图的高度保持在 800 并且不自动调整内容视图的大小?
你可以用 Obj-C 来响应,我会适应 swift 的。
【问题讨论】:
-
为什么不加约束?
-
由于约束,我的内容视图不适合所有滚动视图
标签: ios objective-c swift uiscrollview