I'm using SWRevealViewController and my app is locked on portrait orientation. On one of my view controllers I'm launching a youtube player using the YTPlayerView
. When displaying the video I switch the orientation to landscape programmatically like so:
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
and when exiting the video, back to portrait like so:
let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
All works fine, but introduce a layout issue: the Navigation bar Y is not offsetted by the status bar, resulting the status bar to be on top of the Navigation bar (see screens).
Before orientation change
Playing video on landscape orientation
Navigation bar is being obscured by the status bar
What am I missing here :) ?
Declare a var that will cache initial navigation bar size
Then, in viewDidLoad save the default value
After changing orientation call this method to solve to problem:
This solution is inspired from @Shlomi