views:

99

answers:

1

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

A: 

Hello

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

RickiG
Thanks a lot ! The solution can be so easy :)
Sebastian
One more question, my scroller now fits my layout and the content also has the right size, but when I start in landscape(scrollwidth 1024px) and rotate zu portrait(scrollwidth 768px) I cant use the scroller. When I start in portrait and rotate to landscape, I can only interact in the first 768px, so on the right i can't interact with the scroller. when I go to another view an come back to the view which containts the scrollview, I can use it. So it is not possible to change the scrollView while it is displayed ? Or where should I change it ? thx.
Sebastian
Hi I guess you set up your UIScrollView in either loadView or viewDidLoad? Maybe even init? (this means it is only updated when those functions are called). Try putting the instantiation of the UIScrollView in viewDidLoad, but the setup, changing of content and orientation in a separate function. Now you can call this function from both the viewWillAppear and the ShouldAutoRotate... so the setup happens both when you load it the first time, when you rotate and when you go to another view and back.
RickiG
Can't get it done, either it builds multiple scrollers or it doesn't update the scroller. May I send you a mail with some code, I'm very frustrated ;(
Sebastian
Hi. Try adding your viewController code to your first post. Especially init methods, viewDidLoad, loadView and the shouldAutorotate.You could mail me, but the point is that others should benefit from what we come up with:)
RickiG
You're right ... I added some Code in my first post. And thx for your help, hope we get it working :)
Sebastian