views:

49

answers:

2

I have a run of about 10 different methods, they all pass "page" and "index" between them in order to define a ScrollView with multiple pages. The majority of these methods run within a loop (for each page).

I'm working on a way to re-orient and re-position the pages depending on the device orientation. My trouble now is trying to get access to these multiple pages so I can run a method re-orienting them. Is there a way to loop through the pages and access their information (size, frame, contentSize etc.) so I can then just manipulate them?

A: 

Create a class that knows about the model data, and can divide it up into numbered pages. Now pass that object between your methods, instead of the raw page/index values. Now extend that object to work with your other orientation.

Graham Lee
+1  A: 

You could put a pointer for each view into an array. Then iterating through the array config the Views like this:

-(void)configScrollViewForOriantation:(UIInterfaceOrientation)interfaceOrientation

    //do an if on the oriantation and supply 2 versions...
    //eg..

    if(UIInterfaceOrientationIsPortrait(interfaceOrientation))
    {    
    CGRect f;
    for (UIViewController *page in pageArray) {


    f = page.frame;
    f.size.width = ..;
    f.origin.x = ....;

    page.contentSize = CGSizeMake(newWidth,newHeight)

    //etc

    }
else{
//landscape config
}

}

NB. If you called this method in a CAAffine animation it would animate the changes too.

Ideally you should only make one for loop and set some constants for the configs you are going to do based on the orientation.

Luke Mcneice
How would I generate this array with those pointers? Sorry, I'm kinda new to this. Cheers
Daniel Hanly
Luke Mcneice
thanks mate, you've helped me solve a problem I've been staring at for far too long, I wish I could upvote you again
Daniel Hanly