Reputation: 13
I searched on the web but I didn't find any solution.
That is my problem:
I embed YouTube videos in a UIWebView. It works, but when I enter the fullscreen playback and rotate my iPad, the UINavigationBar is shifted (see the picture below). I know that there is no direct control of the video player in a web view, but I don't know how to solve it.
Thanks
Upvotes: 1
Views: 578
Reputation: 11
It's no way to resolve this problem using MPMoviePlayerNotification, because UIWebView Video Don't use MPMoviePlayerViewController or it's private for developer. But, there's another way to fix this bug.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleStatusBarFrameDidChange)
name:UIApplicationDidChangeStatusBarFrameNotification
object:nil];
- (void)handleStatusBarFrameDidChange {
self.navigationController.navigationBarHidden = YES;
self.navigationController.navigationBarHidden = NO;
}
Upvotes: 1
Reputation: 295
I came across the similar problem on my iPhone app.
I wonder if this is the right way but for now the code below solved it.
1. Added observers in the webivew's initialize method.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
The observers should be removed when you don't need them no longer. I just put the code in the webview's dealloc method.
[[NSNotificationCenter defaultCenter] removeObserver:self];
2. Hide the navigation bar when the movie started and show it again when the movie finished.
* contentsViewController in the code is the owner of my webview. so just in my case.
- (void)youTubeStarted:(NSNotification *)notification
{
self.contentsViewController.navigationController.navigationBarHidden = YES;
}
- (void)youTubeFinished:(NSNotification *)notification
{
self.contentsViewController.navigationController.navigationBarHidden = NO;
}
I got the way from How to receive NSNotifications from UIWebView embedded YouTube video playback
Upvotes: 0