UIScrollView frame size issue in Landscape Mode
- by viper15
I'm trying to make UIScrollView auto-resize and appear correctly in Landscape mode. Portrait mode works fine.
Here's my code:
- (void)viewDidLoad {
[super viewDidLoad];
//=== load all the custom view
NSMutableArray *controllers = [[NSMutableArray alloc] init];
int page = 0;
[controllers addObject:[self loadScrollView:[[Page1ViewController alloc] initWithNibName:@"Page1ViewController" bundle:nil] withPage:page++]];
[controllers addObject:[self loadScrollView:[[Page2ViewController alloc] initWithNibName:@"Page2ViewController" bundle:nil] withPage:page++]];
[controllers addObject:[self loadScrollView:[[Page3ViewController alloc] initWithNibName:@"Page3ViewController" bundle:nil] withPage:page++]];
self.viewControllers = controllers;
[controllers release];
//=== automaticaly define number of pages
_numberOfPages = [self.viewControllers count];
// a page is the width of the scroll view
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * _numberOfPages, scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
// First, set the number of pages
pageControl.numberOfPages = _numberOfPages;
pageControl.currentPage = 0;
}
Then, I went into each view controller nib file and set the background to different color to test if it's working. Unfortunately, when in Landscape mode, the width and height remains the same as in Portrait Mode.
I'm not sure how to fix this problem. Hope anyone can help me.
Many thanks in advance.