2016-11-25 1 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] 

は、その後、あなたのViewControllerにあなたが追加デバイスがオリエンテーションを変更したときのオブザーバー:

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

これは将来の人々に役立つことを願っています。

関連する問題