4

I'm writing a custom modal presentation using iOS 8's UIPresentationController. The controller being presented has a preferred interface orientation UIInterfaceOrientationLandscapeLeft.

Upon presentation of this controller with a UIPresentationController, it is shown in portrait, ignoring the result of the presented controller's preferredInterfaceOrientationForPresentation method.

Presenting View Controller

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)
}

Presented View Controller

override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
    return .LandscapeLeft
}

Is it possible to have UIPresentationController take into account the result of the presented controller's preferredInterfaceOrientationForPresentation method?

Stephane JAIS
  • 1,413
  • 15
  • 14

1 Answers1

1

I answered this on the Apple forums but in case someone stumbles upon this thread from Google..

This is not expected to work. As far as I can tell, the logic to handle the orientation adjustment at presentation time exists only in the private UIPresentationController subclasses used to implement the default presentation styles.

As an aside, a custom presented view controller's -supportedInterfaceOrientations method is normally ignored unless you override -shouldRemovePresentersView in your presentation controller subclass.

Dex
  • 871
  • 4
  • 4
  • Can you link to your answer on Apple forums? What's the proper way to handle orientation in subclasses? – InkGolem May 16 '18 at 17:16
  • This looks to be it: https://forums.developer.apple.com/message/34477#34477 but it's still unclear as to how this is supposed to be implemented. – InkGolem May 16 '18 at 17:30