横向模式下的 tabBarController 和 navigationControllers,第二集 [英] tabBarController and navigationControllers in landscape mode, episode II
问题描述
我有一个 UITabBarController,每个选项卡处理一个不同的 UIViewController,它根据需要在堆栈上推送新的控制器.在我需要的其中两个选项卡中,当到达特定控制器时,能够旋转 iPhone 并在横向模式下可视化视图.在挣扎了很多之后,我发现强制子类化 UITabBarController 来覆盖 shouldAutorotateToInterfaceOrientation.但是,如果我在实现中简单地返回 YES,则会出现以下不良副作用:
I have a UITabBarController, and each tab handles a different UIViewController that pushes on the stack new controllers as needed. In two of these tabs I need, when a specific controller is reached, the ability to rotate the iPhone and visualize a view in landscape mode. After struggling a lot I have found that it is mandatory subclassing UITabBarController to override shouldAutorotateToInterfaceOrientation. However, if i simply return YES in the implementation, the following undesirable side effect arises:
旋转 iPhone 时,每个选项卡中的每个控制器都会自动置于横向模式.
every controller in every tab is automatically put in landscape mode when rotating the iPhone.
即使在每个控制器中重写 shouldAutorotateToInterfaceOrientation 以返回 NO 也不起作用:当 iPhone 旋转时,控制器处于横向模式.
Even overriding shouldAutorotateToInterfaceOrientation in each controller to return NO does not work: when the iPhone is rotated, the controller is put in landscape mode.
我在子类 UITabBarController 中实现了 shouldAutorotateToInterfaceOrientation 如下:
I implemented shouldAutorotateToInterfaceOrientation as follows in the subclassed UITabBarController:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if([self selectedIndex] == 0 || [self selectedIndex] == 3)
return YES;
return NO;
}
因此只有我感兴趣的两个选项卡实际上获得了对横向模式的支持.有没有办法支持特定选项卡堆栈上的特定控制器的横向模式?
So that only the two tabs I am interested in actually get support for landscape mode. Is there a way to support landscape mode for a specific controller on the stack of a particular tab?
我尝试过,但没有成功
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if([self selectedIndex] == 0 || [self selectedIndex] == 3)
{
if ([[self selectedViewController] isKindOfClass: [landscapeModeViewController class]])
return YES;
}
return NO;
}
另外,我尝试使用委托方法 didSelectViewController,但没有成功.任何帮助是极大的赞赏.谢谢.
Also, I tried using the delegate method didSelectViewController, without success. Any help is greatly appreciated. Thank you.
推荐答案
这对我有用:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(self.selectedIndex == 0 && [[[self.viewControllers objectAtIndex:0] visibleViewController] isKindOfClass:[MyViewController class]])
return YES;
else
return NO;
}
这篇关于横向模式下的 tabBarController 和 navigationControllers,第二集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!