Comment faire fonctionner complètement l'application correctement pour l'autorotation dans iOS 6?
-
11-12-2019 - |
Question
Dans iOS6, shouldAutorotateToInterfaceOrientation
est obsolète.J'ai essayé d'utiliser supportedInterfaceOrientations
et shouldAutorotate
pour rendre l'application fonctionnant correctement pour l'autorotation mais a échoué.
Ce mode de vue, je ne veux pas faire pivoter, mais cela ne fonctionne pas.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Des idées? Merci pour une aide à l'avance!
La solution
le figuré.
1) UinavigationController sous-classée (la même vue de la hiérarchie de la hiérarchie prendra le contrôle de l'orientation.)
l'a mis comme Self.Window.rootviewcontroller.
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
-(BOOL)shouldAutorotate
{
return YES;
}
BTW, selon vos besoins, une autre méthode associée:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait;
}
Autres conseils
Si vous utilisez un contrôleur à barres d'onglets au lieu d'un contrôleur de navigation en tant que contrôleur racine, vous aurez besoin de la sous-classement de la même manière uitabbarcontroller.
aussi la syntaxe sera différente.J'ai utilisé ce qui suit avec succès.J'ai ensuite utilisé les exemples ci-dessus avec succès sur les contrôleurs d'affichage que je voulais remplacer.Dans mon cas, je voulais que l'écran principal ne tourne pas, mais j'ai eu un écran FAQ avec des films que j'ai naturellement voulu activer la vue paysagiste.Travaillé parfaitement!Notez simplement le changement de syntaxe sur Self.ModalViewController (vous obtiendrez un avertissement de compilateur si vous essayez d'utiliser la syntaxe pour un contrôleur de navigation.) J'espère que cela vous aidera!
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)shouldAutorotate
{
return self.modalViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.modalViewController.supportedInterfaceOrientations;
}