【问题标题】:Shifted UINavigationBar after rotation during MPMoviePlayer fullscreen playback in a UIWebview在 UIWebview 中 MPMoviePlayer 全屏播放期间旋转后移动 UINavigationBar
【发布时间】:2012-06-11 21:51:40
【问题描述】:

我在网上搜索,但没有找到任何解决方案。

这是我的问题:

我在 UIWebView 中嵌入了 YouTube 视频。它可以工作,但是当我进入全屏播放并旋转我的 iPad 时,UINavigationBar 会移动(见下图)。我知道在网页视图中没有直接控制视频播放器,但我不知道如何解决。

谢谢

Splitted Navigation Bar

【问题讨论】:

  • 我遇到了同样的问题..你是怎么解决这个问题的..谢谢

标签: ipad uiwebview rotation mpmovieplayer navigationbar


【解决方案1】:

使用 MPMoviePlayerNotification 无法解决此问题,因为 UIWebView Video 不要使用 MPMoviePlayerViewController 或者它是开发人员私有的。 但是,还有另一种方法可以修复此错误。

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(handleStatusBarFrameDidChange)
                                             name:UIApplicationDidChangeStatusBarFrameNotification
                                           object:nil];

- (void)handleStatusBarFrameDidChange {
    self.navigationController.navigationBarHidden = YES;
    self.navigationController.navigationBarHidden = NO;
}    

【讨论】:

    【解决方案2】:

    我在我的 iPhone 应用上遇到了类似的问题。

    我想知道这是否是正确的方法,但现在下面的代码解决了它。

    1.在 webivew 的初始化方法中添加了观察者。

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
    

    当您不再需要观察者时,应将其移除。我只是把代码放在webview的dealloc方法中。

    [[NSNotificationCenter defaultCenter] removeObserver:self];
    

    2.电影开始时隐藏导航栏,电影结束时再次显示。
    * 代码中的 contentsViewController 是我的 webview 的所有者。所以就我而言。

    - (void)youTubeStarted:(NSNotification *)notification
    {
        self.contentsViewController.navigationController.navigationBarHidden = YES;
    }
    
    - (void)youTubeFinished:(NSNotification *)notification
    {
        self.contentsViewController.navigationController.navigationBarHidden = NO;
    }
    

    我从How to receive NSNotifications from UIWebView embedded YouTube video playback得到了方法

    【讨论】:

    • 唯一的问题是 UIMoviePlayerController 是一个私有 API。有没有人有使用这些通知成功提交的经验?
    猜你喜欢
    • 1970-01-01
    • 2011-12-28
    • 1970-01-01
    • 1970-01-01
    • 2011-07-16
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    相关资源
    最近更新 更多