Unable to simultaneously satisfy constraints Warnings with AVPlayerViewController embedded in storyboard

后端 未结 6 692
长情又很酷
长情又很酷 2020-12-05 22:50

I\'m trying to set up an AVPlayerViewController completely through storyboards by embedding in a separate View Controller.

Steps:

  1. Create Single View Ap
6条回答
  •  [愿得一人]
    2020-12-05 23:21

    In my case I allow on iPhones only the portrait mode while I want the AVPlayerViewController to have all directions.

    In AppDelegate I have code that looks like this:

    public func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
    
        if self.window?.rootViewController?.presentedViewController is AVPlayerViewController {
    
            return .All
        }
        return Device.current.contains(.iPhone) ? [.Portrait, .PortraitUpsideDown] : .All
    }
    

    When AVPlayerViewController is presented modally, rotated to landscape and dismissed I'll get a very smiler error stack that some constraints broke.

    To workaround I added this code to my RootViewController, which also presents any instance of AVPlayerViewController in my application:

    public override func dismissViewControllerAnimated(flag: Bool, completion: (() -> Void)?) {
    
        if let playerViewController = self.presentedViewController as? AVPlayerViewController {
    
            playerViewController.showsPlaybackControls = false
        }
    
        super.dismissViewControllerAnimated(flag, completion: completion)
    }
    

    Basically I'm catching the moment when the user taps on the dismiss button and use the workaround found in original question post.

提交回复
热议问题