views:

59

answers:

1

I have a scrollview that automatically generates a series of subviews containing imageviews. The concept is that it's pretty much a custom PDF style reader, where each page is loaded in to an imageview as an image. There are three "layers" - the outer UIScrollView, the automatically generated subViews and the imageview inside the subview.

I've been having some trouble with this, I've asked the question previously, but unfortunately, the core of my question was in the wrong place. Here is my second attempt:

On rotate, everything is rotated as needed. Unfortunately, this is what I'm getting: alt text

Obviously, I would like Image 1 to be centred and for there to be no hint of image 2 until you flick the view across.

Here is my code for setting up the view:

- (void)loadView {
    [self setUpView];
}
- (void)setUpView {
    //INITIALISE PAGING SCROLL VIEW
    CGRect pagingScrollViewFrame = [[UIScreen mainScreen] bounds];
    pagingScrollViewFrame.origin.x -= 10;
    pagingScrollViewFrame.size.width += 20;
    pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
    pagingScrollView.contentMode =  UIViewContentModeScaleAspectFit;

    //CONFIGURE PAGING SCROLL VIEW  
    pagingScrollView.pagingEnabled = YES;
    pagingScrollView.backgroundColor = [UIColor blackColor];
    pagingScrollView.contentSize = CGSizeMake(pagingScrollViewFrame.size.width*7, pagingScrollViewFrame.size.height);

    //ACTIVATE PAGING SCROLL VIEW
    self.view = pagingScrollView;

    //ADD PAGES TO SCROLL VIEW
    for (int i = 0; i < 7; i++){
        ImageScrollView *page = [[[ImageScrollView alloc] init] autorelease];
        [self configurePage:page forIndex:i];
        [pagingScrollView addSubview:page];
    }
}

How do I re-define the size of the frame? What function should I call etc. How do I centre the image?

I'm new to this so I apologise for the ambiguity of my question.

Cheers

A: 

I've figured it out. It was the Frame of the individual pages that I needed to change, so (with the help gained from another question) I wrote a re-orient method.

The first step to this came because I figured out that I needed to iterate through and re-size each frame for each of my pages and then re-apply the frames to the view. For this to happen I needed to create an array which I would fill in the For Loop above. I have 7 total pages.

Then I could (on rotate) call the below re-orient method to re-size each view:

- (void) reOrient{
    if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){    
        CGRect f;
        int i = 0;
        for (ImageScrollView *page in pageArray) {          
            f = page.frame;
            f.size.width = 320;
            f.origin.x = (f.size.width * i);
            page.frame = f;
            pagingScrollView.contentSize = CGSizeMake(f.size.width * 7, 480);
            i++;
        }
    }else{
        CGRect f;
        int i = 0;
        for (ImageScrollView *page in pageArray) {          
            f = page.frame;
            f.size.width = 480;
            f.origin.x = (f.size.width * i);
            page.frame = f;
            pagingScrollView.contentSize = CGSizeMake(f.size.width * 7,  480);
            i++;
        }
    }
}
Daniel Hanly