首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UINavigationController supportedInterfaceOrientations:类别与swizzle

UINavigationController supportedInterfaceOrientations:类别与swizzle
EN

Stack Overflow用户
提问于 2014-02-18 22:30:44
回答 2查看 325关注 0票数 2

我在我的tabBarController应用程序中使用了一个带有多个UINavigationControllers的UINavigationControllers,现在我想增加对旋转的支持(在某些视图控制器上,不是全部)。我知道我需要为我的supportedInterfaceOrientation实现UIViewControllers方法。

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

  • 我见过一些人在UINavigationController上创建了一个类别,它覆盖supportedInterfaceOrientation来查询子viewControllers。但我知道,苹果不赞成使用类别来覆盖方法。(我已经像这样实现了它,它运行得很好,但我想确保应用程序继续与未来版本的iOS一起工作。)
  • 那么使用方法swizzling呢?
  • 子类UINavigationController?

如有任何建议请见谅。:)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-18 22:36:19

如果您使用iOS 6+,我建议对UINavigationController进行子类化和重写supportedInterfaceOrientations

类似于:

代码语言:javascript
复制
- (NSUInteger)supportedInterfaceOrientations;
{
  return [self.topViewController supportedInterfaceOrientations];
}
票数 2
EN

Stack Overflow用户

发布于 2014-02-18 22:38:35

您不需要任何子类。只需在每个应对方向更改作出反应的类中添加通知观察者即可。

代码语言:javascript
复制
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenOrientationChanged) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21866880

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档