簡體   English   中英

Tabbar Nav應用程序,允許一個視圖旋轉而其他視圖則不旋轉

[英]Tabbar Nav app, allowing one view to rotate while others do not

我有一個選項卡欄應用程序,其中有3個不同的視圖,每個視圖都有自己的視圖控制器。

在選項卡條形碼中,我具有此功能來處理旋轉。

#import "RotatingTabBarController.h"

@implementation RotatingTabBarController

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

      return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
 }
@end

然后在第二個視圖控制器中,我要根據設備方向旋轉:

// Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

   return YES;
 }

對於我不想旋轉的其他兩個視圖,我設置了此方法。

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

問題:因此,當您旋轉設備時,它們在所需的縱向模式下在視圖1和視圖3中可以正常工作。 在視圖2中,當我旋轉到風景時,視圖會按預期運行並旋轉到風景。 但是,當在視圖2的lanscape模式下單擊視圖1或視圖3的選項卡時,視圖1和視圖3處於橫向模式。

即使視圖2旋轉為橫向,我也無法弄清楚如何以縱向方式強制它們。

有人知道怎么做嗎?

從2008年至今一直對此有一個大討論[1](請看幾頁的評論)–總的來說,

application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;

要么

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

要么

[application setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];

可以讓您將其強制變為橫向景觀-當用戶以編程方式返回到橫向視圖時,您可以執行此操作。

[1] 橫屏模式下的iPhone應用程序,2008系統

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM