2016-11-25 67 views
0

我正在研究一個項目,我想根據設備的方向替換圖標,但不允許viewController旋轉。我有幾個允許旋轉的viewController以及其他,我的導航控制器中指定的不允許旋轉。如何在shouldAutorotate = NO時確定設備方向,只允許縱向顯示?

這個實現工作正是我想要的。

代碼在我的導航控制器:

- (BOOL)shouldAutorotate 
{ 
    id currentViewController = self.topViewController; 

    if ([currentViewController isKindOfClass:[ChimpTabBarController class]]) { 
     ChimpTabBarController *tabbarController = (ChimpTabBarController*)currentViewController; 

     if (tabbarController.selectedIndex == 0){ 
      return NO; 
     } 
    } else if ([currentViewController isKindOfClass:[RotationViewController class]] || [currentViewController isKindOfClass:[ChimpBlackoutVC class]] || [currentViewController isKindOfClass:[EditPictureVC class]]) { 
     return NO; 
    } 
    return YES; 
} 



-(UIInterfaceOrientationMask)supportedInterfaceOrientations{ 
    id currentViewController = self.topViewController; 

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 


    if ([currentViewController isKindOfClass:[ChimpTabBarController class]]) { 
     ChimpTabBarController *tabbarController = (ChimpTabBarController*)currentViewController; 

     if (tabbarController.selectedIndex == 0){ 
      return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown); 
     } 
    } else if ([currentViewController isKindOfClass:[RotationViewController class]] || [currentViewController isKindOfClass:[ChimpBlackoutVC class]] || [currentViewController isKindOfClass:[EditPictureVC class]]) { 
     return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown); 
    } 
    return UIInterfaceOrientationMaskAll; 
} 

有沒有辦法找出哪些輪換我的設備想去,但不允許?所以,我可以改變一個箭頭,文字等...的方向

感謝

回答

0

我已經找到了我自己,而早於預期。

爲您的應用程序,您可以使用:

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 

但是,當旋轉禁用你可以讓你的設備的方向:

[[UIDevice currentDevice] orientation] 

然後在您的視圖 - 控制你添加設備改變方向時的觀察者:

- >How to check Device Orientation Change From Portrait To Landscape and Vice-Versa in iPad

希望這將有助於未來的人。

相關問題