¿Cómo hacer que la aplicación funcione completamente correctamente para la autorotación en iOS 6?

StackOverflow https://stackoverflow.com//questions/12662240

Pregunta

En iOS6, shouldAutorotateToInterfaceOrientation está en desuso.Intenté usar supportedInterfaceOrientations y shouldAutorotate para hacer que la aplicación funcione correctamente para la autorrotación, pero falló.

Este viewcontroller no quiero girar, pero no funciona.

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

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

¿Alguna idea? Gracias por cualquier ayuda por adelantado!

¿Fue útil?

Solución

se lo descubrió.

1) UInvatigationController Subclassed (El ViewController superior de la jerarquía tomará el control de la orientación). lo configuró como self.window.rootviewcontroller.

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

2) Si no desea que View Controller gire

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

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

3) Si desea que pueda girar

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

-(BOOL)shouldAutorotate
{
    return YES;
}

BTW, de acuerdo con sus necesidades, otro método relacionado:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
     return UIInterfaceOrientationMaskPortrait;
}

Otros consejos

Si está utilizando un controlador de barras de pestaña en lugar de un controlador de navegación como controlador de su raíz, deberá subclase de manera similar a UITABBARCONTROLLER.

También la sintaxis será diferente.Usé lo siguiente con éxito.Luego usé los ejemplos anteriores con éxito en los controladores de la vista que quería anular.En mi caso, quería que la pantalla principal no girar, pero tenía una pantalla de preguntas frecuentes con películas que naturalmente quise habilitar la vista del paisaje.¡Funcionó perfectamente!Simplemente tenga en cuenta que la sintaxis cambia a Self.ModalViewController (obtendrá una advertencia de compilador si intenta usar la sintaxis para un controlador de navegación). ¡Espero que esto ayude!

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)shouldAutorotate
{
    return self.modalViewController.shouldAutorotate;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return self.modalViewController.supportedInterfaceOrientations;
}

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top