una forma más limpia es no utilizar UIInterfaceOrientation para la rotación.
Por qué, porque entonces su interfaz o vista 1 realmente gira. Esto significa que tiene que girarlo hacia atrás para volver a mostrarlo después de que se elimine la vista 2. Para compensar esto, simplemente suscribo a UIDeviceOrientation notificaciones. Sutilmente diferente. La vista 1 NO tiene que admitir autorrotación para que este método funcione.En viewDidLoad introduzca el siguiente código:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
A continuación, sólo se define el método detectOrientation:
-(void) detectOrientation {
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
//load view 2
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) {
// load view 1
}
}
Ahora ninguno de sus puntos de vista deben apoyar autoratation! No obstante, tendrá que llevar a cabo una transformación en la visión 2 antes de la carga:
-(void) transformView2ToLandscape {
NSInteger rotationDirection;
UIDeviceOrientation currentOrientation = [[UIDevice currentDevice] orientation];
if(currentOrientation == UIDeviceOrientationLandscapeLeft){
rotationDirection = 1;
}else {
rotationDirection = -1;
}
CGRect myFrame = CGRectMake(0, 0, 480, 300);
CGAffineTransform transform = [[self view2] transform];
transform = CGAffineTransformRotate(transform, degreesToRadians(rotationDirection * 90));
[[self view2] setFrame: myFrame];
CGPoint center = CGPointMake(myFrame.size.height/2.0, myFrame.size.width/2.0);
[[self view2] setTransform: transform];
[[self view2] setCenter: center];
}
Ése es cómo intercambiar puntos de vista o la rotación sin apoyar la auto rotación en mis puntos de vista.
¿Debo hacer una subclase del tabBarController inicial para agregar el método shouldAutorotateToInterfaceOrientation? Este controlador tabBar se ha configurado utilizando IB y unas pocas líneas un código en el delegado de la aplicación. He seguido todos los pasos, pero no se ha llamado a didRotateFromInterfaceOrientation. –
Ok, he subclasificado el tabBarController, agregando shouldAutorotateToInterfaceOrientation y ahora todo funciona. Muchas gracias por su ayuda. Saludos cordiales. –
Prefiero no usar UITabBarController en absoluto y en su lugar usar un UIViewController con una UITabBar. – mk12