當我想在橫向模式下全屏顯示圖像時,遇到了類似的問題,並且它是縱向模式下的默認位置。由於我的應用程序包含一個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