【问题标题】:MPMoviePlayer done button Clicked Change The UIView HeightMPMoviePlayer 完成按钮单击更改 UIView 高度
【发布时间】:2012-01-09 00:20:34
【问题描述】:

我正在使用 MPMoviePlayer 来显示视频。我进入全屏模式,当单击完成按钮时,我希望它从我的视图中删除整个电影播放器​​。

现在,当我单击“完成”按钮时,它会关闭 MPMoviePlayer,但它会改变我的 UIView 高度的大小。有什么解决方案可以在不影响我的视图大小的情况下删除 MPMoviePlayer。

【问题讨论】:

    标签: iphone xcode cocoa-touch ios4


    【解决方案1】:

    创建一个 videoPlayer 视图控制器(MPMoviePlayerViewController 子类)并将其添加到您的根视图控制器。

    videoPlayerViewController = [[VideoViewController alloc] initWithContentURL:[NSURL fileURLWithPath:resourcePath]];
    [rootViewController presentMoviePlayerViewControllerAnimated:videoPlayerViewController];
    videoPlayer.controlStyle = MPMovieControlStyleFullscreen;
    

    然后添加通知:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopVideo:) name:MPMoviePlayerPlaybackDidFinishNotification object:[videoPlayerViewController moviePlayer]];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopVideo:) name:MPMoviePlayerDidExitFullscreenNotification object:[videoPlayerViewController moviePlayer]];                        
    

    然后你的方法在收到通知时被调用。

    - (void) stopVideo:(NSNotification*) aNotification {
      [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:[videoPlayerViewController moviePlayer]];
      [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:[videoPlayerViewController moviePlayer]];
      MPMoviePlayerController *player = [aNotification object];
      [player stop];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多