Estoy trabajando en una aplicación de iPhone basada en UITabBarController y UIViewControllers para cada página. La aplicación necesita para funcionar en modo vertical solamente, por lo que cada delegado controlador de vista + app va con esta línea de código:Detectando la rotación en horizontal manualmente
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Hay un controlador de vista donde me gustaría para que aparezca un UIImageView cuando el iPhone es rotaed a landscapeleft. El diseño de la imagen se ve en el paisaje, aunque el ancho y la altura son 320x460 (por lo que su retrato).
¿Cómo puedo/debo detectar este tipo de rotación manualmente, solo en este controlador de vista específico, sin tener una rotación automática en toda la vista?
Thomas
ACTUALIZACIÓN:
Gracias!
he añadido este escucha en el viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:)name:UIDeviceOrientationDidChangeNotification object:nil];
la didRotate se ve así:
- (void) didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft)
{
//your code here
}
}
Gracias! He añadido este oyente en viewDidLoad: [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (didRotate:) nombre: UIDeviceOrientationDidChangeNotification object: nil]; la didRotate se parece a esto: - (void) didRotate: (NSNotification *) notificación {\t \t orientación UIDeviceOrientation = [[UIDevice currentDevice] orientación]; \t \t si (== orientación UIDeviceOrientationLandscapeLeft) \t { \t \t // su código aquí \t}} –
mejora menor, utilice el UIDeviceOrientationDidChangeNotification constante en lugar de su valor de cadena (que es @ "UIDeviceOrientationDidChangeNotification") –
No te olvides de registrarte como oyente para el evento ... – aroth