Hello all,
I'm trying to create a custom player that uses an AVPlayer and an AVPlayer to play video. I want to enable the user to rotate the device to enter fullsreen and have an animation of the view rotating into lanscape. This is the same functionality that the YouTube app implements. There is a problem with a UINavigationBar that I have in the same view as the player. Since we can no longer keep it a constant size, if I try to change the root view controller, the status bar will change and force the navigation bar into compact mode, which causes unatural transitions in the background. To get around this I have acomplished the functionality I want to achieve in 2 ways, however both have trade offs.
Method 1
- Create a new UIWindow that only supports landscape
- Present the new window as the key window (this preserves the height of the UINavigationBar in the background)
- Move the player into the new window and transform it so it appears in portrait
- Do an animation to unrotate it so it now appears in landscape
There are some issues with this method and moving the player to the new window. The player is not visible for a frame or two, so to combat this I render the player using snapshotView(), add it to the superview of the player, move the window, add a delay onto the main thread and then hide the snapshot. This works but it still causes periodic flashes. When the app goes to the background and comes back to the foreground, the navigation in the background changes into compact mode, so the status bar in the new window has to be shown and hidden, which I have not yet figured out how to get around.
Method 2
- Take a snapshot of the root view using snapshotView()
- Make a new view controller that only supports landscape with the snapshotted view as a subview rotated to appear in portrait
- Move the player into the new view controller and transform it so it appears in portrait
- Do an animation to unrotate it so it now appears in landscape
This resolves many of the artifacts with the other method, but it means that the background content can no longer be dynamic. I do occasionally upate the UI while the view is playing, which causes a jump when the player comes out of fullscreen. I cannot take another snapshot once the player is in fullscreen because the status bar is now hidden and the navigation bar is compact.
I've spent quite a while trying to find a solution to this problem. Is there a proper way to do this? And if there isnt, is there a way to resolve the artifacts that occur with either of the methods that I have already tried?
Thanks