2017-07-11 6 views
0

J'ai des problèmes, ce qui oblige mon application à pivoter à l'envers si je tiens le téléphone à l'envers.iOS (9 et 10) L'application ne pivote pas à l'envers

Je dispose d'un fichier de story-board avec deux scènes: NavigationControllerScenes and MainScene/SettingsScene

Dans le info.plist j'ai vérifié les boîtes pour commencer en mode portrait ou à l'envers orientation.

Dans le délégué de l'application I ajouté:

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

Dans vue Paramètres contrôleur:

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

} 

Dans Mainview contrôleur

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

Il est possible de faire tourner au paysage et portrait, mais pas de portrait à l'envers. Si je décoche la case du portrait dans le fichier info.plist et que seule la case à l'envers est cochée, l'application va se bloquer au début. Ce que je ne comprends pas, je peux utiliser ces extraits de code avec succès dans une application différente avec une seule scène - donc je pense que l'erreur provient de plusieurs scènes. Peut-être que j'ai besoin de créer un navigationController qui remplace certaines méthodes.

Encore une chose: Cela ne fonctionne pas - l'application exécute les instructions, mais rien ne se passe:

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

Dans l'application avec une scène ça marche!

+0

J'espère que ce travail de lien pour vous https://stackoverflow.com/questions/12640870/ios-6-force-device-orientation-to-landscape – Hitesh

Répondre

0

Enfin, je trouve la réponse moi-même:

Créer une classe CustomNavigationController comme suit:

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

Cliquez dans le story-board sur la scène du contrôleur de navigation. Ajouter la classe créée dans la section de classe personnalisée as shown here