iphone uiviewcontroller ios6 landscape-portrait

iphone - Autorote un solo UIViewController en iOS 6 con UITabBar



ios6 landscape-portrait (3)

¿Es la vista que desea rotar una subvista de vista solo de retrato? Por lo general, el comportamiento de rotación de la vista se hereda de rootviewcontroller. Luego, si devuelve NO en el manual de autorización en el controlador de vista de raíz, detendrá la rotación en todas las subvistas.

Sugiero dividir tu arquitectura de esta manera:

rootViewController -> supportedInterfaceOrientations = Portrait & shouldAutorotate = YES NORotationViewControllers -> supportInterfaceOrientations = Portrait & shouldAutorotate = YES rotationViewControllers -> supportInterfaceOrientations = All & shouldAutorotate = YES

Si aún no lo ha leído, eche un vistazo a: Compatibilidad con varias orientaciones de interfaz

Tengo una aplicación que funciona solo en el Portrait Mode , pero hay una vista única que puede mostrar video, así que quiero que la vista también funcione en el landscape mode , pero en iOS 6 no puedo entender cómo puedo hacerlo, ahora Tengo esto:

En AppDelegate.mi tenemos:

self.window.rootViewController = myTabBar;

Luego en el Resumen del proyecto:

y encontré que en iOS 6 para detectar la rotación de vista tengo que hacer esto:

- (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } // Tell the system It should autorotate - (BOOL) shouldAutorotate { return YES; }

así que inserto el código anterior solo en mi UIViewController que quiero usar también en horizontal, pero no funciona, ¿alguien sabe cómo puedo hacerlo? Solo quiero el autorotate cuando muestro el video.


En primer lugar, la configuración de destino debe tener este aspecto:

En UITabBarController:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // You do not need this method if you are not supporting earlier iOS Versions return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; } -(NSUInteger)supportedInterfaceOrientations { if (self.selectedViewController) return [self.selectedViewController supportedInterfaceOrientations]; return UIInterfaceOrientationMaskPortrait; } -(BOOL)shouldAutorotate { return YES; }

Dentro de su ViewController:

a) Si no quieres rotar:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; }

b) si quieres rotar al paisaje:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - (BOOL)shouldAutorotate { return YES; } - (NSInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAllButUpsideDown; }

Editar:

Otra solución es implementar este método dentro de AppDelegate:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { NSUInteger orientations = UIInterfaceOrientationMaskAll; if (self.window.rootViewController) { UIViewController* presented = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject]; orientations = [presented supportedInterfaceOrientations]; } return orientations; }


Escribiría un comentario pero no puedo, así que estoy publicando esto como una respuesta.

Este fue mi escenario:

Mi aplicación soporta la orientación cambiando solo en ciertos puntos de vista y no pude averiguar cómo hacerlo solo para los que quería, luego me dirigí a esta pregunta y vi la respuesta de Mientus (Gracias por esto), seguí adelante e hice lo que sugirió cuál era la subclase UITabBarController y anular estos métodos:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ NSLog(@"AUTO ROTATE IN CUSTOM TAB BAR"); // You do not need this method if you are not supporting earlier iOS Versions return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; } -(NSUInteger)supportedInterfaceOrientations{ NSLog(@"supportedInterfaceOrientations IN CUSTOM TAB BAR"); if (self.selectedViewController) return [self.selectedViewController supportedInterfaceOrientations]; return UIInterfaceOrientationMaskPortrait; } -(BOOL)shouldAutorotate{ NSLog(@"shouldAutorotate IN CUSTOM TAB BAR"); return [self.selectedViewController shouldAutorotate]; }

Luego, dentro de cada controlador de vista, tendría los métodos para indicar si quería rotación o no. Los métodos en UITabBarController se llamaban, pero no los de mi controlador de vista, por lo que la rotación todavía estaba sucediendo donde no quería. Luego, subclasifico UINavigationController y anulo los mismos métodos solo con este cambio en el SupportInterfaceOrientation para que se vea así:

- (NSUInteger)supportedInterfaceOrientations{ NSLog(@"supportedInterfaceOrientations IN CUSTOM NAV BAR CALLING CURRENT VIEW CONTROLLER"); UIViewController* presented = [[self viewControllers] lastObject]; return [presented supportedInterfaceOrientations];

}

lo que esto hace básicamente es obtener el controlador de vista actual y luego solicita la orientación admitida y voila mis métodos en mi controlador de vista, y puedo manejar la orientación donde lo desee.