2010-11-23 36 views
2

我已經使用代碼創建了UIWebView,我使用initWithFrame來定義啓動尺寸。默認情況下,當我旋轉設備時,沒有任何東西旋轉,方向與開始時相同。只允許在UIWebView上進行方向/旋轉更改

的應用是基於UITabController和所有選項卡在控制器中不顯示UIWebViews和那裏我不要允許整個應用程序進行旋轉。

所以我有兩個問題。

  • 是否有可能只允許旋轉UIWebView的內容?
  • 如果上述不可行,如何在旋轉(應用程序委託?)時刪除TabBar,並且是否需要刷新UIWebView的內容以跨越窗口跨越它?

回答

3

當我想在橫向模式下全屏顯示圖像時,遇到了類似的問題,並且它是縱向模式下的默認位置。由於我的應用程序包含一個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它會自動內適當地適應內容,而不必以「刷新」本身。

+0

您還可以使標籤欄控制器有條件地允許旋轉取決於選擇哪個標籤。由於您可能以橫向模式隱藏標籤欄,因此除非用戶處於肖像模式,否則用戶無法進入其他標籤頁。只有在選擇的選項卡是包含webView的視圖的情況下才允許旋轉 – leukosaima 2010-11-23 21:02:11