When embedding an AVPlayerViewController in a portrait only iOS app it seems the app can get stuck in a weird layout when the player exits full screen if the video is full-screened while the device is held in a landscape orientation.
Is this a bug or am I doing something incorrectly?
Here's how to reproduce with a clean project using Xcode 9.4.1, swift 4, iOS 11.4, simulator or physical device.
ViewController.swift
override func viewDidLoad() {
super.viewDidLoad()
//Create the player and add as child view controller
let playerVC = AVPlayerViewController()
self.addChildViewController(playerVC)
//Place player's view in self
playerVC.view.frame = CGRect(x: 10, y: 40, width: 355, height: 200)
self.view.addSubview(playerVC.view)
//Load example video
playerVC.player = AVPlayer(url: URL(string: "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")!)
}
How it works normally:
- Play video, hit full screen
- Rotate to landscape, video rotates
- Close full screen, app returns to portrait regardless of screen or device orientation
- ex: https://imgur.com/a/MPFmzyH
How it breaks:
- Play video, rotate device to landscape (screen does not rotate)
- Hit full screen
- Exit full screen
- Screen breaks, rotating does not fix
- ex: https://imgur.com/a/hDdmu20