Mudança de orientação necessária, mas apenas para uma das várias visualizações no TabBarViewController
-
20-09-2019 - |
Pergunta
Meu aplicativo possui um uitabbarcontroller com cinco guias. Eu precisava girar as orientações apenas para a quinta guia. Consegui fazer com que todos os cinco girassem para a paisagem subclassendo o uitabbarcontroller
@implementation TabBarControllerRotate
-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight
|| interfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| interfaceOrientation == UIInterfaceOrientationPortrait);
}
@fim
if(tbc == nil){
//tbc = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
tbc = [[TabBarControllerRotate alloc] initWithNibName:nil bundle:nil]; ////// new //////
....
tbc.viewControllers =
[NSArray arrayWithObjects:viewController1, viewController2, viewController3
,viewController4,viewController5, nil];
Agora preciso desligar a rotação do ViewController1 - 4; Tentei, sem sucesso, fazer isso adicionando o código a seguir aos quatro arquivos *.m para esses ViewControllers.
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
Por favor, aconselhe -me sobre como terminar o R. Obrigado pela leitura, Mark
Solução
Suponho que existem outras maneiras mais fáceis de fazer isso, mas finalmente recebi uma solução. O título do quinto ViewController no TabbarController, o único que precisa mudar de orientação, é "mynotes"
Dentro do sublistViewController.M, o objeto TabBarControllerTratate é criado.
tbc = [[TabBarControllerRotate alloc] initWithNibName:nil bundle:nil]; tbc.viewControllers = [NSArray arrayWithObjects:viewController1 , viewController2, viewController3, viewController4, viewController5, nil tbc.delegate = self;
Subclasses TabBarController UITABBARController e inclui um nome de propriedade bool bmynotes.
Sublistviewcontroller é um uitabbarcontrollerDelegate
Cada vez que a visualização é alterada no TabBarController, uma mensagem é enviada, a saber, - (void) TabBarController: (UitabBarController *) TabBarController DidSelectViewController: (UIViewController *) ViewController
Portanto, o sublistViewController.m contém este código:
#pragma mark UITabBarControllerDelegate methods - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ BOOL b = (viewController.title == @"MyNotes"); [tbc setBMyNotesTab:b]; //NSLog(@"MyNotesTab == %d", [tbc bMyNotesTab]); }
Em seguida, TabBarControllerTrotate.m contém:
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { //NSLog(@"bMyNotesTab is: %d",self.bMyNotesTab); return ( (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationPortrait ) && self.bMyNotesTab );
}