我正在子类化 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/