调整UIScrollView中的内容视图的大小无效

我有这个ViewController:

主视图
_-滚动
__-内容视图

我需要dynamic调整内容视图

我有这个方法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 

在这一步,两个视图都正确resize。

在我的滚动事件中,我已经链接了这个方法:

 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 

所以,当我开始滚动,我的内容视图被调整…

我的问题是:我必须做什么来保持我的内容视图的高度,当我滚动,而不是我的内容视图的这个autoresizing?

你可以用Obj-C来回应,我会适应它。

尝试这个

 - (void) fitForScroll:(UIView*) containerViewInScroll :(UIScrollView*)scrollView { float w=0; float h=0; for (UIView *v in [containerViewInScroll subviews]) { float fw = v.frame.origin.x + v.frame.size.width; float fh = v.frame.origin.y + v.frame.size.height; w = MAX(fw, w); h = MAX(fh, h); } [containerViewInScroll setFrame:CGRectMake(containerViewInScroll.frame.origin.x,containerViewInScroll.frame.origin.y, w, h + 20)]; [scrollView setContentSize:containerViewInScroll.frame.size]; } ----------