我正在使用iOS 8的UIPresentationController编写自定义模式演示文稿。显示的控制器具有首选的界面方向UIInterfaceOrientationLandscapeLeft
。
在使用UIPresentationController呈现此控制器时,它以纵向显示,忽略了所呈现的控制器的preferredInterfaceOrientationForPresentation方法的结果。
呈现视图控制器
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let controller = segue.destinationViewController as? UIViewController {
controller.modalPresentationStyle = .Custom
controller.transitioningDelegate = self
}
}
func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return nil
}
func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return nil
}
func presentationControllerForPresentedViewController(presented: UIViewController,
presentingViewController presenting: UIViewController!,
sourceViewController source: UIViewController) -> UIPresentationController? {
return UIPresentationController(presentedViewController: presented, presentingViewController: presenting)
}
显示视图控制器
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return .LandscapeLeft
}
是否可以让UIPresentationController考虑所呈现的控制器的preferredInterfaceOrientationForPresentation方法的结果?
答案 0 :(得分:1)
我在Apple论坛上回答了此问题,但万一有人偶然发现Google的这个帖子。
这不会起作用。据我所知,在演示时处理方向调整的逻辑仅存在于用于实现默认表示样式的私有UIPresentationController子类中。
除此之外,通常会忽略自定义呈现的视图控制器的-supportedInterfaceOrientations方法,除非您在表示控制器子类中覆盖-shouldRemovePresentersView。