문제

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 !!

도움이 되었습니까?

해결책

[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)];
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top