自动调整大小UIScrollView [英] Autoresize UIScrollView

查看:73
本文介绍了自动调整大小UIScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个UIViewController,它以编程方式生成一个UIScrollView.一切都很好,但是当我旋转设备时,UIScollView应该调整大小,以使其占据我的View的整个宽度.

I made a UIViewController, which programatically generates a UIScrollView. Everything's fine, but when I rotate the Device, the UIScollView should resize so it takes the complete width of my View.

有没有一种方法而无需重建完整的UIScrollView?

Is there a way to do that without rebuilding the complete UIScrollView ?

非常感谢!塞巴斯蒂安

这在我的viewDidLoad中被调用:

This is called in my viewDidLoad:

    -(void)buildmyScroller {
    myScroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 800, 768, 100)];


    //...adding some subviews to myScroller


    thumbScroller.contentSize = CGSizeMake(3000, 100);
    [[self view] addSubview:myScroller];
}

然后我尝试以此来调整myScroller的大小,当我使用setFrame时,我说myScroller不会对其进行响应...:

Then I tried to resize myScroller with this, when I used setFrame, I said myScroller would not respond to it... :

-(void)changemyScroller {
        UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;
    if (interfaceOrientation == UIInterfaceOrientationPortrait) {
        [thumbScroller setFrame:CGRectMake(0, 805, 768, 150)];
    }
    else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
        thumbScroller.frame = CGRectMake(0, 805, 768, 150);
    }
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
        thumbScroller.frame = CGRectMake(0, 549, 1024, 150);
    }
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
        thumbScroller.frame = CGRectMake(0, 549, 1024, 150);
    }
}

并在didAnimateFirstHalf中调用了该方法...因为我不知道还有什么地方可以调用它.

And called the method in didAnimateFirstHalf... cause I'm not shure where else to call it.

再次感谢!

推荐答案

[scrollView setFrame:CGRectmake(x,y,width,height)];//也许您需要对scrollView的内容执行相同的操作,以使其适合您的布局

[scrollView setFrame:CGRectmake(x, y, width, height)]; //Maybe you need to do the same for the content of the scrollView to make it fit your layout

应该这样做.如果需要进行过渡,则可以将其包装在UIAnimation块中.

should do it. You can wrap that in an UIAnimation block if it need to be a transition.

这篇关于自动调整大小UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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