自动调整 UIScrollView 大小

发布于 2024-09-06 06:25:07 字数 1337 浏览 3 评论 0原文

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

有没有办法在不重建完整 UIScrollView 的情况下做到这一点?

非常感谢! Sebastian

这是在我的 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 不会响应它...:

-(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 中调用该方法...因为我不确定在哪里否则就可以调用它。

再次非常感谢!

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.

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

Thx a lot !
Sebastian

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

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

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

Thx a lot again !!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没有伤那来痛 2024-09-13 06:25:07

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

应该这样做。如果需要过渡,您可以将其包装在 UIAnimation 块中。

[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

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

累赘 2024-09-13 06:25:07

试试这个:

    if(self.rowNumber == 0){
    /******************* Scroller Setup *****************/
    // how many pages
    int pageCount = 5;
    //set up the scrollView
    UIScrollView *scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 960)];
    // support for Landscape Orienation
    if(UIInterfaceOrientationLandscapeLeft){
        [scroller  setFrame:CGRectMake(0,0,1024, 704)];
    }
    if(UIInterfaceOrientationLandscapeRight){
        [scroller  setFrame:CGRectMake(0,0,1024, 704)];
    }

Try this:

    if(self.rowNumber == 0){
    /******************* Scroller Setup *****************/
    // how many pages
    int pageCount = 5;
    //set up the scrollView
    UIScrollView *scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 960)];
    // support for Landscape Orienation
    if(UIInterfaceOrientationLandscapeLeft){
        [scroller  setFrame:CGRectMake(0,0,1024, 704)];
    }
    if(UIInterfaceOrientationLandscapeRight){
        [scroller  setFrame:CGRectMake(0,0,1024, 704)];
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文