开发者

Autoresize UIScrollView

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 开发者_如何学JAVAI'm not shure where else to call it.

Thx a lot again !!


[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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜