Sono stato a questo per alcuni fine settimana per capire la soluzione corretta, ho provato molte altre soluzioni ma semplicemente non ha funzionato correttamente. Se vuoi che solo l'interfaccia utente sia in orizzontale o verticale prova questo metodo qui sotto. Sto eseguendo Xcode 7.2.1, sto usando un Bool per impostare il valore insieme a NSUSerDefaults in ogni classe che voglio seguire specifici UIInterfaceOrientations. Il metodo qui sotto viene chiamato ogni volta che viene presentata una nuova UI o quando il dispositivo viene ruotato, è possibile verificarlo inserendo un NSLog verificando il valore del bool in quel metodo e verificando di persona come cambia.
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:
In te AppDelegate effettuare le seguenti operazioni
@property .h (assegnare, nonatomic) BOOL shouldRotate;
.m
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED{
_shouldRotate = [[NSUserDefaults standardUserDefaults]boolForKey:@"rotateKey"];
NSLog(@"Did I get to InterfaceOrientation \n And the Bool is %d",_shouldRotate);
if (self.shouldRotate == YES)
return UIInterfaceOrientationMaskAllButUpsideDown;
else
return UIInterfaceOrientationMaskPortrait;
}
ormai in ogni classe che si desidera avere un UIInterfaceOrientation SPECIFICO fare questo
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
// [[AppDelegate sharedAppDel]setShouldRotate:YES];
BOOL rotate = NO;
[[NSUserDefaults standardUserDefaults]setBool:rotate forKey:@"rotateKey"];
[[NSUserDefaults standardUserDefaults]synchronize];
}
-(BOOL)shouldAutorotate
{
return YES;
}
le viste che si desidera ruotare modificare il valore Bool a Sì. Ora nel tuo AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
BOOL rotate = NO;
[[NSUserDefaults standardUserDefaults]setBool:rotate forKey:@"rotateKey"];
[[NSUserDefaults standardUserDefaults]synchronize];
return YES;
}
anche nel vostro AppDelegate
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
BOOL rotate = NO;
[[NSUserDefaults standardUserDefaults]setBool:rotate forKey:@"rotateKey"];
[[NSUserDefaults standardUserDefaults]synchronize];
}
Spero che questo aiuti molti sviluppatori. Testato e testato molte volte.
saluti
JZ
fonte
2016-03-23 17:47:30
MAI tacere un avviso (a meno che non sei un esperto che si è risposto motivo per cui è una buona idea). Correggi il codice. – gnasher729
@ gnasher729 OP significava ovviamente "quell" o "soddisfa" l'avviso, non tacendo a titolo definitivo. –