我在我的iPhone应用程序中使用带有多个UINavigationController的tabBarController,现在我想添加对旋转的支持(在某些视图控制器上,不是全部)。我知道我需要为我的 UIViewController 实现支持的 InterfaceOrientation 方法。
当设备旋转时,支持的接口方向在UINavigationController上调用,但我需要在视图控制器上调用它。最好的方法是什么?
-
我见过有些人在UINavigationController上创建了一个类别,该类别覆盖了支持的InterfaceOrientation以查询子视图控制器。但我知道苹果不喜欢使用类别来覆盖方法。(我已经像这样实现了它,它工作正常,但我想确保该应用程序继续适用于未来版本的 iOS。
-
使用方法旋转怎么样?
-
子类UINavigationController?
任何建议表示赞赏。 :)
如果您使用iOS 6+,我建议UINavigationController
子类化并覆盖supportedInterfaceOrientations
类似于:
- (NSUInteger)supportedInterfaceOrientations;
{
return [self.topViewController supportedInterfaceOrientations];
}
你不需要子类任何东西。只需在每个应该对方向更改做出反应的类中添加通知观察器
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenOrientationChanged) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];