2012-10-17 23 views
6

我在我的應用程序中使用主控制器和詳細控制器的自定義分割視圖控制器。支持不同視圖控制器在iOS 6.0中的不同方向

- (id)initWithMasterController:(UIViewController*)aMasterController 
      detailedController:(UIViewController*)aDetailedController; 

提供給主控制器和細節上的控制器控制器的UINavigationController。

由於我的應用程序的一部分,有兩種可能的情況下,進行定向處理:

  1. 當控制器六個組合在主和細節控制器的使用,所有的方向都支持的應用程序。
  2. 單獨在細節控制器上有一個StudentDetailsViewController時,只能支持兩種可能的方向。 (風景)

當過設備的方向發生改變,下面的事情發生版本的iOS以下6.0

  1. -shouldAutorotateToInterfaceOrientation:方法被調用。該方法的實現如下:在運行時,我將請求轉發給主控制器,並使用相同的調用將詳細控制器轉發給控制器。

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    { 
        BOOL res = [masterController shouldAutorotateToInterfaceOrientation:interfaceOrientation] 
           && [detailedController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
        return res; 
    } 
    
  2. masterController的-shouldAutorotateToInterfaceOrientation將返回TRUE。下面是StudentViewController中該方法的實現。

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    { 
        return (IS_IPAD) ? UIInterfaceOrientationIsLandscape(interfaceOrientation) 
            : UIInterfaceOrientationIsPortrait(interfaceOrientation); 
    } 
    

以獲得新的定向信息被改變的能力幫我決定是否轉動應啓用。

與iOS 6.0:

當過設備的方向發生改變,下面的東西的iOS 6.0

版本
  1. 拆分視圖控制器的方法-shouldAutorotate發生被調用。它的實施是低於

    - (BOOL)shouldAutorotate { 
        BOOL res = [masterController shouldAutorotate] 
           && [detailedController shouldAutorotate]; 
        return res; 
    } 
    
  2. 的detailedController的shouldAutorotate調用navigationController。自動旋轉功能的StudentsController實施:

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

但與iOS 6.0,我無法控制的方向。儘管supportedInterfaceOrientations方法被調用,但在detailsController的shouldAutorotate方法調用StudentsDetailsController的shouldAutorotate方法時,shouldAutorotateMethod不遵守supportedInterfaceOrientations方法中提到的選項。

UPDATE:

我閱讀文檔,並在document提供了下面的註解。

有時您可能希望動態禁用自動旋轉。例如,對於 示例,如果要在短時間內完全禁止旋轉 ,則可以執行此操作。您必須暫時禁用想要手動控制 狀態欄位置的 方向更改(例如,當您調用 setStatusBarOrientation:animated:方法時)。

如果要暫時禁用自動旋轉,請避免使用 操縱方向遮罩來執行此操作。請改爲在最頂端的視圖控制器上覆蓋shouldAutorotate方法 。在執行任何自動旋轉之前調用此方法爲 。如果它返回NO,那麼將禁止旋轉 。

是否可以暫時禁用基於當前方向的自動旋轉?

+0

的代碼格式無法正確完成.. – Krishnan

+0

你有沒有解決這個問題?我有同樣的問題,無法弄清楚如何處理這兩個ios5和6 – Stas

+0

沒有我沒有解決它.. – Krishnan

回答

0

我相信這是iOS中的一些問題,其中rootViewController沒有參考childViewController的首選方向。但是,你應該嘗試類似以下內容:

if (self.interfaceOrientation != UIInterfaceOrientationPortrait) 
{ 
    [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationPortrait]; 
} 

改變方向回縱向對於給定的觀點。

0

在您的應用程序中,委託類定義了以下方法,該方法在應用程序中的任何其他旋轉方法之前被調用。

創建一個標誌(isRotationEnabled),它將決定你的應用程序的方向。

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {  

return self.isRotationEnabled ? 
    UIInterfaceOrientationMaskAll : 
    UIInterfaceOrientationMaskPortrait; 
} 

變化根據你不同的條件下,這種標誌的應用程序使用下面的代碼

MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 
appDelegate.isRotationEnabled = NO; 
相關問題