繁体   English   中英

在UIScrollView中调整内容视图的大小无法正常工作

[英]Resize content view in UIScrollView no working

我有这个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做出回应,我会尽快对其进行调整。

尝试这个

- (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];
}


----------

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM