UIScrollView frame size issue in Landscape Mode

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.

Answers


I'm having the same problem, but only if I open the view in Landscape, when it was designed in the .xib in Portrait.

If I open in portrait, then rotate the device, it sizes correctly.

I've found that if I load my view controllers array in viewWillAppear, rather than in viewDidLoad, it sizes correctly all the time.


Need Your Help

Add/Remove items from one set to form a subset

user-interface widget

What is it called when you have a box with all of the elements from a set and you have buttons to add/remove those items to form a subset of those items?

Cesium : Using own OpenStreetMap server. : 'Failed to obtain image tile' Error

javascript linux ubuntu openstreetmap cesium

Following guide at switch2osm.org I was able to get my own OSM tile server running.