Extremely weird behavior of navigationBar and MPMoviePlayerController. Bug in iOS or my error?

三世轮回 提交于 2019-12-01 04:47:54

Ok, so I found this freaking same bug all over my app first in a UIWebView then in a MPMoviePlayerController, I solved this placing this code in my view controller.

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

Tricky bugs, tricky fixes.

If you listen for the MPMoviePlayerWillExitFullscreenNotification notification, you can force your main views to redraw properly as follows. The 'window' referenced is your application's main UIWindow object.

When MPMoviePlayerController switched to fullscreen, it actually creates a separate UIWindow instance to present the video. By catching the notification as it transitions back, this code will ensure the views you're switching back to correctly realign.

Admittedly, this is not an elegant solution, but it does work every time.

UIView *view = [window.subviews lastObject];
if (view) {
     [view removeFromSuperview];
     [window addSubview:view];
}

To listen for this notification, you'll need to do something like this, where self.playerController is your MPMoviePlayerController object.

Remember to stop listening for this notification once you release the player though!

    // Determine the default notification centre
    NSNotificationCenter *centre = [NSNotificationCenter defaultCenter];
    // Listen for interesting movie player notifications
    [centre addObserver: self
               selector: @selector(onPlayerWillExitFullScreen:) 
                   name: MPMoviePlayerWillExitFullscreenNotification 
                 object: self.playerController];
- (void) moviePlayerWillExitFullScreen:(id)sender {

[[UIApplication sharedApplication]setStatusBarHidden:NO withAnimation:NO];

}

Guys try this... It works for me. I tried many other ways and only this one worked.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!