Mudança Vista em apenas uma guia em Tabbar-Aplicação (Landscape-Retrato)?
-
19-09-2019 - |
Pergunta
Como posso alterar a vista durante a rotação do iphone (da mudança nib). Mas isso só deve acontecer em uma única guia! Eu tentei com:
- (void)viewDidLoad {
LandscapeViewController *viewController = [[LandscapeViewController alloc]
initWithNibName:@"LandscapeView" bundle:nil];
self.landscapeViewController = viewController;
[viewController release];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification object:nil]; }
- (void)orientationChanged:(NSNotification *)notification
{
[self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}
- (void)updateLandscapeView
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self presentModalViewController:self.landscapeViewController animated:YES];
isShowingLandscapeView = YES;
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
}
Mas então a Paisagem-View aparece em todas as guias. (Uma vez que quando esse código é carregado). Alguma idéia?
Solução 3
Tanks por seus comentários! Eu encontrei uma solução alternativa:
//Remove Observer if not in Landscape
- (void)viewDidDisappear:(BOOL)animated {
if (isShowingLandscapeView == NO) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
}
//Add Observer if not in Landscape
- (void)viewDidAppear:(BOOL)animated {
if (isShowingLandscapeView == NO) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
}
Outras dicas
O que está acontecendo é o seu controlador de exibição está recebendo a notificação UIDeviceOrientationDidChangeNotification
sempre que as alterações de rotação, se é ou não está sendo exibido. Em vez de tentar usar o built-in métodos de UIViewController
que são destinados para responder às rotações.
Esta é a partir Docs (View Controller Guia de Programação) da Apple:
Controllers Tab Bar e Ver rotação
controladores de barra de abas apoiar um retrato orientação por padrão e não rotação para uma orientação horizontal a menos que toda a exibição de raiz controladores de suportar tal orientação. Quando um dispositivo de orientação mudança ocorre, o controlador de barra guia consulta a sua variedade de controladores de vista. Se qualquer um deles não suporta a orientação, a barra de guia O controlador não mudar a sua orientação.
Então, eu não tenho certeza que o Bar Controlador Tab é projetado para rodar apenas para uma única exibição.