2

I am working on an iOS app using Objective-C. Running latest xCode at time of post (7.1.1) and running on an iOS 9.1 simulator and iPhone 6.

My app is locked in portrait. 1 section of the app has a UIWebView. The UIWebView can have a video embedded on it. When the user plays the video, it allows them to rotate their device to landscape (which is the expected behavior). However, once they do and click "Done" on the video, the status bar starts to overlap with the navigation bar (see linked screenshot).

Status Bar overlapping UINavigationBar

There are other places in the app where I am natively presenting a MPMoviePlayerViewController and rotation has no effect on the status or navigation bars.

Any thoughts?

user1302023
  • 31
  • 1
  • 1
  • 9

2 Answers2

0

The issue here is handling device rotation properly as you move around your UIViews. This is common in video playback where the video needs to be landscape but everything else portrait. Here are a few good links: Forcing landscape orientation on fullscreen MPMoviePlayerController prevents correct rotation when exiting fullscreen, What is the "right" way to handle orientation changes in iOS 8?. Bob McCune wrote the Learning AV Foundation book and has some good sample code on his github repo https://github.com/bobmccune. If you need more specifics on sample code let me know and I can provide other links.

As a simple quick fix you could just try removing display of the status bar, but that's not the appropriate thing to do.

I can post more sample code links if you need so you can see how this is done. That's probably the best approach short of having you provide some of your code.

Community
  • 1
  • 1
xdeleon
  • 769
  • 8
  • 20
  • The thing is I'm not presenting the MPMoviePlayerController, the UIWebView is by default. `ViewWill` and `ViewDidAppear` are oddly not called when the user dismisses the MPMoviePlayerController. – user1302023 Dec 11 '15 at 01:48
  • Check your layout constraints. This link might help: http://stackoverflow.com/questions/19078278/is-there-any-way-to-add-constraint-between-a-view-and-the-top-layout-guide-in-a. Also, you might want to track for completion of video playback events and then adjust/fix the position of the navigation bar manually. Here are two similar questions showing how to track those events: http://stackoverflow.com/questions/21453177/statusbar-issue-on-uiwebview-embedded-youtube-video-playback, http://stackoverflow.com/questions/6598537/how-to-rotate-an-uiwebview-embedded-video – xdeleon Dec 11 '15 at 18:04
0
- (void)viewDidLoad {

    self.navigationBarCenterY = self.navigationController.navigationBar.center.y;
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(handleWindowDidBecomeHiddenNotification:)
                                                 name:UIWindowDidBecomeHiddenNotification
                                               object:self.view.window];
}

- (void)handleWindowDidBecomeHiddenNotification:(NSNotification *)notify
{
    if (self.navigationController.navigationBar.center.y != self.navigationBarCenterY) {
        self.navigationController.navigationBar.center = CGPointMake(self.navigationController.navigationBar.center.x, self.navigationBarCenterY);
    }
}
Bo Persson
  • 90,663
  • 31
  • 146
  • 203