2
我正在嘗試使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;
}
於是,我走進了每個視圖控制器榫文件和背景設置成不同的顏色,以測試它的工作。不幸的是,在橫向模式下,寬度和高度與縱向模式下保持一致。
我不知道如何解決這個問題。希望任何人都可以幫助我。 非常感謝提前。