Ver posición incorrecta cuando se establece en el modo de paisaje
-
21-09-2019 - |
Pregunta
Mi aplicación para iPhone está basado en la navegación y contiene una gran cantidad de retratos de sólo puntos de vista y uno horizontal solamente ver para ver imágenes. Así que me gustaría para obligar a este punto de vista horizontal solamente para rotar automáticamente a LANscape incluso si el dispositivo se coloca en el modo vertical.
Así que aquí es lo que I'w realiza en el controlador de ese punto de vista:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void)viewWillAppear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
_originalTransform = [[appDelegate navigationController].view transform];
_originalBounds = [[appDelegate navigationController].view bounds];
_originalCenter = [[appDelegate navigationController].view center];
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
landscapeTransform = CGAffineTransformTranslate (landscapeTransform, +80.0, +100.0);
[[appDelegate navigationController].view setTransform:landscapeTransform];
[appDelegate navigationController].view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[appDelegate navigationController].view.bounds = CGRectMake(0.0, 0.0, 480.0, 320.0);
[appDelegate navigationController].view.center = CGPointMake (240.0, 160.0);
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
}
}
- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
[self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[[appDelegate navigationController].view setTransform:_originalTransform];
[[appDelegate navigationController].view setBounds:_originalBounds];
[[appDelegate navigationController].view setCenter:_originalCenter];
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
}
Ahora tengo esa visión siempre se muestra en el modo de paisaje. Pero hay un problema. Este punto de vista está colocado incorrectamente como se muestra en la captura de pantalla .
He intentado establecer manualmente el marco después de la rotación, pero no sirvió de nada. Además no he encontrado una guía completa de cómo configurar una vista a ser horizontal solamente. Por favor me ayude con este problema.
Solución
Salida posterior href="https://stackoverflow.com/questions/181780/is-there-a-documented-way-to-set-the-iphone-orientation/186589#186589"> . Básicamente lo que necesita para transformar todo el centro de la ventana. Parece que también tenga que girar la barra de estado.
Un método diferente sería utilizar UIDevice setDeviceOrientation, pero eso es una API privada y por lo tanto no es una buena solución.
Otros consejos
Trate de usar este método después de haber aplicado la transformación:
[self.view sizeToFit];