0

Using this code to allow the media players to rotate in landscape (which is not supported by the app) while they are in fullscreen :

// handle orientation for the device
func application (_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    guard let vc = (window?.rootViewController?.presentedViewController) else {
        return .portrait
    }
    if (vc.isKind(of: NSClassFromString("AVFullScreenViewController")!)) || (vc.isKind(of: NSClassFromString("YTPlayerView")!)) {
        return .allButUpsideDown
    } else {
        return .portrait
    }
}

working fine in ios 10 but since ios 11 the screen will not rotate back after leaving fullscreen, thus not resizing the UI (the app will after rotation occupy only half of the screen). It seems there were some modification on avkit but I cannot find any resources on this, thoughts?

thibaut noah
  • 1,474
  • 2
  • 11
  • 39

2 Answers2

1

I got the same problem this day. The solution is to check if iOS11 is running. If so, just return UIInterfaceOrientationMask.portrait else return the desired value. in iOS 11 the video can rotate even if only the portrait is enabled in the project settings.

Example:

if #available(iOS 11, *) {
   return UIInterfaceOrientationMask.portrait
} else {
   guard let vc = (window?.rootViewController?.presentedViewController) else {
      return .portrait
   }

   if (vc.isKind(of: NSClassFromString("AVFullScreenViewController")!)) || (vc.isKind(of: NSClassFromString("YTPlayerView")!)) {
      return .allButUpsideDown
   } else {
      return .portrait
   }
}
clemens
  • 16,716
  • 11
  • 50
  • 65
Tomo Norbert
  • 770
  • 4
  • 13
  • In my case, in iOS11, If I played the video fullscreen, rotated the screen to landscape and exited the video, the original ViewController would be in landscape (App is portrait only). I tried several things but this approach was the easiest and works as intended. – Tomo Norbert Dec 08 '17 at 16:36
  • That's because you didn't return .portrait for your original VC as intended mate. – thibaut noah Dec 12 '17 at 09:23
0

IOS 11 seems to support this out of the box, meaning the code must be remove if the user runs ios 11, leaving the fullscreen will automatically put the video where it is supposed to be, the parent screen will not rotate with the video.

thibaut noah
  • 1,474
  • 2
  • 11
  • 39