UIScrollView在横向模式下的帧尺寸问题

问题描述:

我正在尝试使UIScrollView自动调整大小并在横向模式下正确显示。肖像模式正常工作。 这里是我的代码:UIScrollView在横向模式下的帧尺寸问题

- (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; 

}

于是,我走进了每个视图控制器榫文件和背景设置成不同的颜色,以测试它的工作。不幸的是,在横向模式下,宽度和高度与纵向模式下保持一致。

我不知道如何解决这个问题。希望任何人都可以帮助我。 非常感谢提前。

我有同样的问题,但只有当我在Landscape中打开视图时,它是在Portrait中的.xib中设计的。

如果我以纵向打开,然后旋转设备,它的尺寸正确。

我发现,如果我在viewWillAppear中加载我的视图控制器数组,而不是在viewDidLoad中,它始终正确调整大小。