2013-02-15 69 views
0

上次我運行我創建的iOS應用程序時,它一定是用於部署目標5.0和相關SDK(有可能早在4.3)。部署現在是6.1。我的應用程序只運行景觀,並在景觀中運行良好。但在我更新了我的iPad和iOS SDK並在大約一年後第一次運行此應用程序後,似乎有所改變。iOS應用程序的iPad方向 - 自新版本

這些按鈕顯示爲iPad處於縱向模式。這是錯誤的,因爲它應該是在橫向(並且它曾經工作得很好)。

最新更新有哪些變化?

我在Xcode中支持的界面方向只有「風景右側」被選中,並且在信息部分中,我有「支持的界面方向」,只有一個項目:「風景(右側主頁按鈕)」。

在打開的應用程序第一次打開時,我有

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || 
      interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
} 

,也是viewDidLoad的第一行是

self.view.frame = CGRectMake(0, 0, 1024, 768); 

所以我的主視圖控件爲什麼代碼繪製按鈕爲如果它處於肖像模式?


UPDATE

我試圖與

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationLandscapeRight & UIInterfaceOrientationLandscapeLeft; 
} 

更換shouldAutorotateToInterfaceOrientation方法,但它仍然無法正常工作。

+0

所以,現在部署目標是iOS的6.1? – jamapag 2013-02-15 20:47:01

+0

是的,沒錯。 – CodeGuy 2013-02-15 20:47:18

+0

'應該在iOS 6中棄用shouldAutorotateToInterfaceOrientation'。 – jamapag 2013-02-15 20:49:05

回答

0

iOS6中的方向更改。0

你應該如果您正在使用TabBarController/NavigationController實現以下方法

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

// Set the initial preferred orientation 
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeRight; 
} 

注意
你應該子類的視圖控制器覆蓋以這樣一種方式,它應該叫定向方法你擁有視圖控制器方法。這是iOS6的重大變化。

#import "UINavigationController+Orientation.h" 

@implementation UINavigationController (Orientation) 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return [self.topViewController supportedInterfaceOrientations]; 
} 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

@end 
0

shouldAutorotateToInterfaceOrientation在iOS 6中已過時,應重寫的UIViewController

supportedInterfaceOrientations方法有引自DOC:

在iOS 6中,您的應用支持在 應用程序的定義的接口方向Info.plist文件。視圖控制器可以覆蓋 supportedInterfaceOrientations方法以限制支持的 方向的列表。一般來說,系統只會在窗口視圖控制器的根目錄控制器或視圖控制器上顯示填充 整個屏幕;子視圖控制器使用其父視圖控制器爲其提供的窗口部分,並且不再支持 直接參與有關旋轉 支持的決策。應用程序的方向遮罩和視圖控制器的方向遮罩的交集用於確定視圖控制器可以旋轉到哪個方向。

您可以覆蓋旨在以全屏顯示 特定方向的視圖控制器的preferredInterfaceOrientationForPresentation( )。

+0

我已將shouldAutorotateToInterfaceOrientation替換爲supportedInterfaceOrientations(請參閱上面的更新),但問題仍然存在。有任何想法嗎? – CodeGuy 2013-02-15 20:58:32

+0

還需要設置'self.window.rootViewController'在'應用中:didFinishLaunchingWithOptions:',比如'self.window.rootViewController = navigationController;'。 – jamapag 2013-02-18 11:17:51

相關問題