2017-07-11 1 views
0

Ich habe Probleme und zwinge meine App, auf den Kopf zu drehen, wenn ich das Telefon auf den Kopf halte.iOS (9 & 10) App dreht sich nicht auf dem Kopf

Ich habe eine Storyboard-Datei mit zwei Szenen: NavigationControllerScenes and MainScene/SettingsScene

Im info.plist mir die Kisten eingecheckten Porträt starten oder auf dem Kopf Orientierung.

Im AppDelegate ich hinzugefügt:

#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; 
    } 

In Settings-View-Controller:

 - (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; 
    } 

} 

In Hauptansicht-Controller

 - (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; 
    } 

Es ist möglich, Landschaft und Porträt zu drehen, aber nicht um kopfüber zu porträtieren. Wenn ich das Kästchen Portrait in der Datei info.plist deaktiviere und nur das umgekehrte Kästchen aktiviert habe, stürzt die App gleich am Anfang ab. Also ich denke, eine Einstellung fehlt ...

Was ich nicht bekomme ist, kann ich diese Code-Schnipsel in einer anderen App mit nur einer Szene erfolgreich verwenden - so denke ich, der Fehler kommt aus mehreren Szenen. Vielleicht muss ich einen NavigationController erstellen, der einige Methoden überschreibt.

Eine weitere Sache: Dies funktioniert nicht - der App, die Anweisungen ausführt, aber nichts passiert:

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

In der App mit einer Szene es funktioniert!

+0

ich für Sie auf diesen Link Arbeit hoffen https://stackoverflow.com/questions/12640870/ios-6-force-device-orientation-to-landscape – Hitesh

Antwort

0

Schließlich fand ich die Antwort selbst:

eine CustomNavigationController Klasse erstellen, wie folgt:

// .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 

Im Klick auf die Navigationssteuerung Szene Storyboard. In Abschnitt wird die erstellte Klasse in der benutzerdefinierten Klasse as shown here

Verwandte Themen