横向模式下的UIScrollView帧大小问题

时间:2010-03-15 21:47:03

标签: iphone iphone-sdk-3.0 uiscrollview uiscrollviewdelegate

我正在尝试使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;

}

然后,我进入每个视图控制器nib文件并将背景设置为不同的颜色以测试它是否正常工作。不幸的是,在横向模式下,宽度和高度保持与纵向模式相同。

我不确定如何解决这个问题。希望有人能帮助我。 提前谢谢了。

1 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,但只有当我在Landscape中打开视图时,才会在Portrait中的.xib中进行设计。

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

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

相关问题