2017-07-11 5 views
0

携帯電話を逆さまにしていると、アプリが上下逆さまに回転するようになります。iOS(9&10)アプリが逆さまに回転しない

私は2つのシーンとストーリーボードファイルがあります:Info.plistの中 NavigationControllerScenes and MainScene/SettingsScene

を私は肖像画や逆さ向きで起動するボックスをチェックします。私は追加アプリデリゲートで

:セッティングにおいて

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 
    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
    #else 
    - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
    #endif 
    { 
     return UIInterfaceOrientationMaskPortrait; 
    } 

コントローラを表示:MAINVIEWコントローラ内

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation // iOS 6 autorotation fix 
    { 
     return UIInterfaceOrientationPortraitUpsideDown; 
    } 


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

    - (BOOL)shouldAutorotate // iOS 6 autorotation fix 
    { 
     return YES; 
    } 
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
    { 
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
     if (self) { 
      // Custom initialization 
     } 
     return self; 
    } 

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 
     - (NSUInteger)supportedInterfaceOrientations{ 
    #else 
    - (UIInterfaceOrientationMask)supportedInterfaceOrientations 
    #endif 
    { 
     return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; 
    } 

} 

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation // iOS 6 autorotation fix 
    { 
     return UIInterfaceOrientationPortraitUpsideDown; 
    } 


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

    - (BOOL)shouldAutorotate // iOS 6 autorotation fix 
    { 
     return YES; 
    } 
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
    { 
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
     if (self) { 
      // Custom initialization 
     } 
     return self; 
    } 


    #if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 
      - (NSUInteger)supportedInterfaceOrientations 
    #else 
    - (UIInterfaceOrientationMask)supportedInterfaceOrientations 
    #endif 
    { 
     return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; 
    } 

風景やポートレートに回転させることが可能です、肖像画を上下逆さまにすることはできません。 info.plistでポートレートのチェックボックスをオフにして、上下反転ボックスのみをオンにすると、アプリが最初に正しくクラッシュします。 設定が欠落していると思います...

私は何もわかりませんが、私は正常に1つのシーンだけ異なるアプリケーションでこれらのコードスニペットを使用できます - エラーは複数のシーンから来ていると思います。 たぶん、いくつかのメソッドをオーバーライドするnavigationControllerを作成する必要があります。

もう一つ: これは動作しません - アプリは文を実行しますが、何も起こりません:それは作品1つのシーンにアプリで

NSNumber * value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown]; 
[[UIDevice currentDevice] setValue:value forKey:@"orientation"]; 

を!

+0

私はあなたのために、このリンク作業を願ってカスタムクラスのセクションhttps://stackoverflow.com/questions/12640870/ios-6-force-device-orientation-to-landscapeで作成したクラスを追加 – Hitesh

答えて

0

は最後に、私は自分自身の答えを見つけました:

次のようにCustomNavigationControllerクラスを作成します。ナビゲーションコントローラシーンの絵コンテをクリックして

// .h file 
#import <UIKit/UIKit.h> 
@interface CustomNavigationController : UINavigationController 
@end 

// .m file 
#import "CustomNavigationController.h" 

@interface CustomNavigationController() 

@end 

@implementation CustomNavigationController 

- (BOOL)shouldAutorotate 
{ 
    return self.topViewController.shouldAutorotate; 
} 
- (NSUInteger)supportedInterfaceOrientations 
{ 
    return self.topViewController.supportedInterfaceOrientations; 
} 

@end 

を。 as shown here

関連する問題