【发布时间】:2010-10-19 21:12:21
【问题描述】:
我有一个 UITabBarController,每个选项卡都处理一个不同的 UIViewController,它根据需要将新控制器推送到堆栈上。在其中两个选项卡中,当到达特定控制器时,我需要旋转 iPhone 并在横向模式下可视化视图的能力。经过一番挣扎后,我发现强制继承 UITabBarController 来覆盖 shouldAutorotateToInterfaceOrientation。但是,如果我在实现中简单地返回 YES,则会出现以下不良副作用:
旋转 iPhone 时,每个选项卡中的每个控制器都会自动进入横向模式。
即使在每个控制器中覆盖 shouldAutorotateToInterfaceOrientation 以返回 NO 也不起作用:当 iPhone 旋转时,控制器处于横向模式。
我在子类UITabBarController中实现了shouldAutorotateToInterfaceOrientation如下:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if([self selectedIndex] == 0 || [self selectedIndex] == 3)
return YES;
return NO;
}
所以只有我感兴趣的两个选项卡才能真正支持横向模式。 有没有办法为特定选项卡的堆栈上的特定控制器支持横向模式?
我尝试过,但没有成功,类似
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if([self selectedIndex] == 0 || [self selectedIndex] == 3)
{
if ([[self selectedViewController] isKindOfClass: [landscapeModeViewController class]])
return YES;
}
return NO;
}
另外,我尝试使用委托方法 didSelectViewController,但没有成功。 任何帮助是极大的赞赏。 谢谢。
【问题讨论】:
标签: iphone uiviewcontroller uitabbarcontroller landscape