tabBarController和navigationControllers在横向模式中,第二集 [英] tabBarController and navigationControllers in landscape mode, episode II
问题描述
我有一个UITabBarController,每个标签处理一个不同的UIViewController,根据需要推送堆栈的新控制器。我需要在其中两个选项卡中,当达到特定控制器时,能够旋转iPhone并以横向模式显示视图。经过艰苦的努力,我发现必须继承UITabBarController以覆盖shouldAutorotateToInterfaceOrientation。但是,如果我只是在实现中返回YES,则会出现以下不良副作用:
旋转iPhone时,每个选项卡中的每个控制器都会自动进入横向模式。 / p>
甚至覆盖每个控制器中的shouldAutorotateToInterfaceOrientation以返回NO不起作用:当iPhone旋转时,控制器处于横向模式。
我在子类UITabBarController中实现了shouldAutorotateToInterfaceOrientation,如下所示:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if([self selectedIndex] == 0 || [self selectedIndex] == 3)
返回YES;
返回NO;
}
因此,我感兴趣的两个标签实际上只能获得横向模式的支持。
有没有办法在特定标签的堆栈上支持特定控制器的横向模式?
我试过,但没有成功,像是
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if([self selectedIndex] == 0 || [self selectedIndex] == 3)
{
if([[self selectedViewController] isKindOfClass:[landscapeModeViewController class]])
返回YES;
}
返回NO;
}
此外,我尝试过使用委托方法didSelectViewController,没有成功。
非常感谢任何帮助。
谢谢。
这对我有用:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(self.selectedIndex == 0&& [[[self.viewControllers objectAtIndex:0] visibleViewController] isKindOfClass:[MyViewController class]])
返回YES;
其他
返回NO;
}
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:
every controller in every tab is automatically put in landscape mode when rotating the 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.
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?
I tried, without success, something like
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if([self selectedIndex] == 0 || [self selectedIndex] == 3)
{
if ([[self selectedViewController] isKindOfClass: [landscapeModeViewController class]])
return YES;
}
return NO;
}
Also, I tried using the delegate method didSelectViewController, without success. Any help is greatly appreciated. Thank you.
This worked for me:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(self.selectedIndex == 0 && [[[self.viewControllers objectAtIndex:0] visibleViewController] isKindOfClass:[MyViewController class]])
return YES;
else
return NO;
}
这篇关于tabBarController和navigationControllers在横向模式中,第二集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!