在 UIScrollView 中调整内容视图的大小不起作用 [英] Resize content view in UIScrollView no working

查看:28
本文介绍了在 UIScrollView 中调整内容视图的大小不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 ViewController :

I have this ViewController :

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

Main View
_-Scroll
__- content view

我需要动态调整内容视图的大小

I need to resize dynamically the content view

我有这个方法resizeScrollView(),这是我的方法:

I have this method resizeScrollView(), this is my method :

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

在这一步,两个视图都正确调整了大小.

At this step, both views are correctly resized.

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

On my scrolling event, i have link this method :

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

当我滚动时,我看到这些日志:

And when i'm scrolling, i see these logs :

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

因此,当我开始滚动时,我的内容视图会调整大小...

So, when i am starting to scrolling, my content view is resized...

我的问题是:当我滚动时我必须做些什么才能将我的内容视图的高度保持在 800 并且没有自动调整我的内容视图的大小?

My question is : What i have to do to keep my content view's height to 800 when i am scrolling and not have this autoresizing of my content view?

您可以使用 Obj-C 进行响应,我会使其适应 swift.

You can respond with Obj-C, i'll adapt it to swift.

推荐答案

试试这个

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


----------

这篇关于在 UIScrollView 中调整内容视图的大小不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆