我有一个包含4个视图的tabBarController。我希望第二个视图旋转,所以我添加了
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return YES;
}
到我所有的4个viewControllers。现在每个视图都可以旋转,这很好。
第二个视图在旋转时工作正常,它可以很好地处理其内容的大小调整和重绘。 (现在其他视图轮流但不更新其内容,我将继续处理)
问题是,如果我留在第一个视图中,旋转手机,然后移动到第二个视图,所有内容都会以奇怪的方式调整大小。
例如,我在第二个视图上有一个scrollView,覆盖了所有屏幕。当我在第二个视图中旋转手机时,它会调整滚动视图的大小以适应横向屏幕,一切正常。但是,如果我将手机旋转到第一个视图(或第三个视图或第四个视图中),滚动视图会变小,不到屏幕的一半。
用于调整大小并重新绘制我正在使用的内容:
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation]; }
- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft ||
orientation == UIInterfaceOrientationLandscapeRight) {
sfondo.frame = CGRectMake(0, 0, 480, 260);
scrollView.frame = CGRectMake(0, 0, 480, 250);
scrollView.contentSize = CGSizeMake(480,1000);
for (int i=0; i<3; i++) {
[[grafici objectAtIndex:i] landscapeMode:TRUE];
}
}
else if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown) {
sfondo.frame = CGRectMake(0, 0, 320, 411);
scrollView.frame = CGRectMake(0, 0, 320, 411);
scrollView.contentSize = CGSizeMake(320,1100);
for (int i=0; i<3; i++) {
[[grafici objectAtIndex:i] landscapeMode:FALSE];
}
}
}
答案 0 :(得分:0)
我发现问题是因为我已经从Interface Builder设置了我的scrollview和其他东西。
以编程方式执行此操作解决了我的问题!