ios - UINavigationController 支持的InterfaceOrientations : category vs swizzle

标签 ios iphone objective-c-category

我在 iPhone 应用程序中使用带有多个 UINavigationController 的 tabBarController,现在我想添加对旋转的支持(在某些 View Controller 上,而不是全部)。我知道我需要为我的 UIViewController 实现supportedInterfaceOrientation 方法。

当设备旋转时,在 UINavigationController 上调用supportedInterfaceOrientation,但我需要在我的 viewControllers 上调用它。最好的方法是什么?

  • 我看到有些人在 UINavigationController 上创建了一个类别,该类别覆盖了supportedInterfaceOrientation来查询子viewControllers。但我知道苹果不赞成使用类别来覆盖方法。 (我已经像这样实现了它,并且运行良好,但我想确保该应用程序继续与 future 版本的 iOS 一起使用。)

  • 使用方法调配怎么样?

  • 子类 UINavigationController?

任何建议表示赞赏。 :)

最佳答案

如果您使用iOS 6+,我建议子类化UINavigationController并覆盖supportedInterfaceOrientations

类似于:

- (NSUInteger)supportedInterfaceOrientations;
{
  return [self.topViewController supportedInterfaceOrientations];
}

关于ios - UINavigationController 支持的InterfaceOrientations : category vs swizzle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21866880/

相关文章:

iphone - 如何在 View 上制作关闭图标(红色 x)?

objective-c - Swift 代码看不到在 Objective-C 类别中声明的方法

ios - 快速自定义 UIView

ios - 尝试在 View 不在 Windows 层次结构中的 uinavigationcontroller 上呈现 uiview Controller

iphone - 当点击iPhone中的UIButton时如何保持选中状态?

iphone - 如何在应用程序中检测 iPhone 操作系统版本?

objective-c - 如何在命名类别中声明私有(private)属性?

ios - 类别中 self 和[ self 类]之间的区别?

ios - 我可以从测试 iPhone 上的应用程序恢复源代码吗 --Swift/Objective C

ios - 想要发送自定义电子邮件,即使用 Swift 3.0 来自 firebase 的欢迎邮件