当我想在横向模式下全屏显示图像时,遇到了类似的问题,并且它是纵向模式下的默认位置。由于我的应用程序包含一个TabBarController,每个选项卡都显示一个导航控制器,所以我必须使用“willAnimateRotationToInterfaceOrientation”来移动包含该图像的视图。
在我的应用程序中,标签栏控制器将在所有方向上显示,但肖像倒置。如果您将标签栏控制器锁定到一个方向,我相信您也会锁定标签栏中的所有后续视图。本质上,我隐藏状态栏,导航栏和标签栏,同时将导航栏向上移出视图,并将标签栏向下移出视图,并调整中间内容的大小。这里是什么,我做了一个例子,假设你有self.WebView(这将是我的图像,例如):
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
float navBarHeight = self.navigationController.navigationBar.frame.size.height;
float tabBarHeight = ((UITabBarController *)self.navigationController.parentViewController).tabBar.frame.size.height;
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
float statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.navigationController.navigationBar.hidden = YES;
((UITabBarController *)self.navigationController.parentViewController).tabBar.hidden = YES;
// TabBarController adjustments
self.navigationController.parentViewController.view.bounds = CGRectMake(0, -tabBarHeight/2, 480, 320 + tabBarHeight);
// Adjust view
self.view.frame = CGRectMake(0, -statusBarHeight - navBarHeight, 480, 320);
// Adjust web view
self.WebView.frame = CGRectMake(26, 0, 426.6667, 320);
}
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
float statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
self.navigationController.navigationBar.hidden = NO;
((UITabBarController *)self.navigationController.parentViewController).tabBar.hidden = NO;
// TabBarController adjustments
self.navigationController.parentViewController.view.bounds = CGRectMake(0, 0, 320, 480);
// NavigationController adjustments
self.navigationController.navigationBar.frame = CGRectMake(0, statusBarHeight, 320, navBarHeight);
// Adjust view
self.view.frame = CGRectMake(0, statusBarHeight + navBarHeight, 320, 480 - statusBarHeight - navBarHeight - tabBarHeight);
// Adjust web view
self.WebView.frame = CGRectMake(0, 0, 320, 240);
}
}
我相信通过调整你的WebView它会自动内适当地适应内容,而不必以“刷新”本身。
您还可以使标签栏控制器有条件地允许旋转取决于选择哪个标签。由于您可能以横向模式隐藏标签栏,因此除非用户处于肖像模式,否则用户无法进入其他标签页。只有在选择的选项卡是包含webView的视图的情况下才允许旋转 – leukosaima 2010-11-23 21:02:11