更改选项卡时忽略自动旋转
我有一个带有UITabBarController的应用程序,每个选项卡都有一个附加的UINavigationController。现在让我们假设选项卡1,2和4中的rootViewControllers(navigationControllers)仅支持纵向方向,并且具有这样的shouldAutorotateToInterfaceOrientation实现,当要求旋转为纵向时,该实现仅返回YES。然而,Tab 3在其navigationController中有一些viewControllers支持横向。
I have an application with a UITabBarController, each of the tabs has a UINavigationController "attached" to it. Now lets assume that the rootViewControllers (of the navigationControllers) in Tabs 1,2 and 4 only support the portrait orientation and have such a "shouldAutorotateToInterfaceOrientation" implementation that only returns YES when asked to rotate to portrait. Tab 3 however has some viewControllers in its navigationController that support landscape orientation.
当我现在进入选项卡3并移动到支持横向的viewControllers时,我能够将设备和界面更改为横向。然而,如果我在横向模式下使用界面点击标签1,2或4,则界面不会变回纵向但保持横向,尽管显示的viewControllers显然只支持肖像。
When I am in tab 3 now and move to one of the viewControllers that support landscape I am able to turn the device and the interface changes to landscape. Yet if I hit tab 1,2 or 4 with the interface in landscape mode, the interface does not get changed back to portrait but stays in landscape, despite the fact that the displayed viewControllers clearly only support portrait.
我不确定我缺少什么或者这是否是预期的行为,我希望通过tabBarController切换到仅肖像viewController后,界面方向切换回肖像。整个层次结构是以编程方式构建的。
I am unsure as to what I am missing or whether this is intended behavior, I would like the interface orientation to switch back to portrait once I switch to a portrait only viewController via the tabBarController. The entire hierarchy is constructed programmatically.
谢谢!
我在我的一个应用程序上遇到与您相同的问题,区别在于我没有在选项卡项中使用导航控制器。
I was having the same issue as you on one of my apps, with the difference that I was not using navigation controllers in the tab items.
我最终为UITabBarController创建了一个类别(因为它不是要被子类化的),方法是shouldAutorotate ...
I ended up creating a category for the UITabBarController (since it's not meant to be subclassed) for the method shouldAutorotate...
@implementation UITabBarController (orientation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
#if DEBUG
NSLog(@"UITabBarController (orientation) -> shouldAutorotateToInterfaceOrientation: [%d]",toInterfaceOrientation);
#endif
//if(toInterfaceOrientation == UIInterfaceOrientationPortrait) return YES;
// else return [self.selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
if (self.selectedViewController == [self.viewControllers objectAtIndex:kLibraryStoreTabIndex])
return NO;
if( self.selectedViewController == [self.viewControllers objectAtIndex:kContactTabIndex]){
return YES;
}
// rest of the conditions depending of the tab
return NO; //last option
}