iOS 8 - change orientation back to portrait when dismissing full screen AVPlayerViewController iOS 8 - change orientation back to portrait when dismissing full screen AVPlayerViewController swift swift

iOS 8 - change orientation back to portrait when dismissing full screen AVPlayerViewController


Rather than implementing application(_:supportedInterfaceOrientationsForWindow:) try implementing supportedInterfaceOrientations() on each view controller. So for example:

override func supportedInterfaceOrientations() -> Int {    return Int(UIInterfaceOrientationMask.Portrait.rawValue)}

This will ensure that the view controller cannot be displayed in landscape, so when dismissing the video player, it will come straight back to a portrait window.

Update Objective-C:

- (NSUInteger)supportedInterfaceOrientations {     return UIInterfaceOrientationMaskPortrait; } 


Add These Lines in Appdelegate and your Required View Controller

-(BOOL)shouldAutorotate{    return NO; }-(NSUInteger)supportedInterfaceOrientations{    //LandScapeMode:- UIInterfaceOrientationMaskLandscape;    //PortraitMode:-     return UIInterfaceOrientationMaskPortrait }- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{    //LandScapeMode:- UIInterfaceOrientationLandscapeRight;   // ProtraitMode:-   return UIInterfaceOrientationPortrait}


What i did to fix this issue, create a new class with a 'viewDidLayoutSubviews' function and override it!

final class NewMoviePlayerViewController: AVPlayerViewController {    override func viewDidLayoutSubviews() {        super.viewDidLayoutSubviews()        if view.bounds == contentOverlayView?.bounds {            let value = UIInterfaceOrientation.portrait.rawValue            UIDevice.current.setValue(value, forKey: "orientation")        }    }}