2012-10-10 61 views
3

我有一個應用程序,通常是一個肖像應用程序,只顯示一個UIViewController的橫向視圖。它可以正常工作,直到新的iOS 6發佈。iOS 6方向問題

我真的不明白iOS 6中的方向如何工作。於是我寫了一個測試應用程序。這是我做的:

  • 設置應用程序的方向以支持所有的方向。

enter image description here

  • 我用故事板。 rootViewController嵌入在縱向的UINavigationController中。

enter image description here

  • 在RootViewController的代碼:

    - (NSUInteger)supportedInterfaceOrientations

    {

    回報UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;

}

  • 當我點擊打開欄按鈕,我會推這應該是在風景模式另一個(SecondViewController)視圖控制器:

    - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; }

雖然此方法調用正確,但第二個視圖控制器始終也處於縱向模式。

有人可以給我一些建議嗎?由於

+1

看看這有助於:http://stackoverflow.com/questions/12519693/unable-to-handle-orientation-in-ios-6 –

回答

1

這裏是我的解決方案:

在第二視圖控制器的viewDidLoad:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIViewController *viewController = [[UIViewController alloc] init]; 
    [self presentViewController:viewController animated:NO completion:^{ 
     [viewController dismissViewControllerAnimated:NO completion:nil]; 
    }]; 
} 

這將迫使旋轉到其解決我的問題橫向第二種觀點。它適用於iOS 5和6.

+0

應用程序崩潰。 –

0

我認爲最好的解決方案是堅持官方的蘋果文檔。所以根據我的說法,我使用以下方法,並且iOS 5和6上的所有功能都運行良好。 在您的所有ViewControllers中重寫以下方法。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return UIInterfaceOrientationIsPortrait(interfaceOrientation); 
} 

方法的iOS 6,支持定位面具第一個方法返回(作爲其名稱中標明),你可以把它變成橫向或什麼套房,爲您最好的。

-(NSInteger)supportedInterfaceOrientations{ 

    return UIInterfaceOrientationMaskPortrait; //UIInterfaceOrientationMaskPortrait or LandscapeLeft ... 
} 

第二個告訴你的VC哪個是首選的界面方向,當VC要顯示時。

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationPortrait; //tells your VC in which orientation it should be presented, if you set Porttrait it would be in Portrait or otherwise ... 
} 

該解決方案是工作順利,我不喜歡創建宏和其他東西的想法,去解決這個簡單的解決方案。 希望這個幫助...

1

對於iOS-6,我已經做到了這一點。它運行良好

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ 
    return UIInterfaceOrientationLandscapeLeft;} 

在第二視圖

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ 
    return YES;}