ios - 如何在导航 Controller iOS 10 中正确覆盖 supportedInterfaceOrientations?

标签 ios

我正在子类化 UINavigationController 并覆盖 supportedInterfaceOrientations 方法。在该方法中,我委托(delegate)给 visibleViewController.supportedInterfaceOrientations
但是,当我以模态方式呈现 UIImagePickerController 时,visibleViewController 为 nil .
iOS 10 中发生了一些变化,导致 visibleViewController 返回 nil。
如果我更改代码以使用 presentedViewController,它会正确返回 UIImagePickerController

这是正确的更改吗?为什么会发生这种变化?

最佳答案

听起来你可以使用 setOverrideTraitCollection(_:forChildViewController:) — — (我想你可以用 UIImagePickerController 实现类似的东西):

func setOverrideTraitCollection(_ collection: UITraitCollection?, 
     forChildViewController childViewController: UIViewController)

Normally, traits are passed unmodified from the parent view controller to its child view controllers. When implementing a custom container view controller, you can use this method to change the traits of any embedded child view controllers to something more appropriate for your layout. Making such a change alters other view controller behaviors associated with that child. For example, modal presentations behave differently in a horizontally compact versus horizontally regular environment. You might also make such a change to force the same set of traits on the child view controller regardless of the actual trait environment.

↪︎ Video Presentation from WWDC 2016 : Making Apps Adaptive, Part 1 and 2

Apple 有 recommended使用较新的 API UITraitCollection UITraitEnvironment在尝试适应 supportedInterfaceOrientations 前进...

关于ios - 如何在导航 Controller iOS 10 中正确覆盖 supportedInterfaceOrientations?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40002314/

相关文章:

ios - swift ios 我应该使用核心数据还是数组/结构

ios - NSPredicate 不替换 %@ 参数 - Swift 4

ios - 如何实现 "sort by"和 "filter by"的项目?

再次打开设备或互联网后,iOS 未收到待处理的 APNs 推送通知

ios - 如何在不写代码的情况下在iOS模拟器中设置位置?

objective-c - IOS中的套接字断开

ios - Swift Firebase 链接两个节点

iphone - 如何将uitoolbar添加到uitableviewcontroller?

ios - 从 parse 迁移到 azure 不适用于移动应用程序

iOS 11 [NSTimeZone localTimeZone] 忽略 [NSTimeZone defaultTimeZone];