ios - MPMoviePlayerViewController观看后隐藏StatusBar并销毁Frame

标签 ios objective-c mpmovieplayercontroller statusbar

我在我的 UIView 中创建了一个 MPMoviePlayerViewController (不是在我的 UIVIewController 中!),如下所示:

self.playButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 70, 125, 100)];
                        [self.playButton setBackgroundImage:[UIImage imageNamed:@"video_play.png"] forState:UIControlStateNormal];
                        [self.playButton addTarget:self action:@selector(buttonPressed:) forControlEvents: UIControlEventTouchUpInside];


                        self.playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];

self.playerViewController.moviePlayer.fullscreen = NO;
self.playerViewController.view.frame = CGRectMake(0, 0, 320, 200);

[self.playerViewController.moviePlayer prepareToPlay];
self.playerViewController.moviePlayer.shouldAutoplay = NO;
self.playerViewController.view.backgroundColor = [UIColor yellowColor];
[self addSubview:self.playerViewController.view];
[self.playerViewController.view addSubview:self.playButton];

}

- (void)buttonPressed:(id)sender{
(NSLog(@"Click"));

[self.playerViewController.moviePlayer setFullscreen:YES animated:YES];
[self.playerViewController.moviePlayer play];
}

正如你所看到的,我在 videoView 上添加了一个按钮,因为这部分应该只是预览,当用户单击该按钮时,MPMoviePlayerViewController 应该动画到全屏并开始播放,当视频完成时它应该去返回预览 View 。到目前为止一切正常,但我有两个问题:

第一个问题: 每次我打开 View 时,我的状态栏都会隐藏起来,如下所示:

enter image description here

所以我在 UIViewController 的 viewWillAppear 和 viewDidAppear 中设置:

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

这可行,但现在状态栏被隐藏并立即再次出现,看起来很难看,有机会解决这个问题吗?

第二个问题:

当我单击“自定义”按钮时,视频将全屏显示并且一切正常!但是,当我按下视频的“完成”按钮时,一切都会返回到预览屏幕,看起来像这样:状态栏被隐藏,导航栏也被破坏,并且视频上方有很多黑色空间,这里有什么问题?

enter image description here

最佳答案

好吧,我找到了这个问题的解决方案,它有点老套,但我没有找到其他解决方案。在我的 ViewController 中我这样做:

- (void)viewDidLoad {
   [super viewDidLoad];

    float delay = 0.1;

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC),  dispatch_get_main_queue(), ^{
    [UIApplication sharedApplication].statusBarHidden = NO;
});

对于用户点击后退按钮的情况,我这样做:

- (void)viewDidAppear:(BOOL)animated {
   [super viewDidAppear:animated];

   [UIApplication sharedApplication].statusBarHidden = NO;
}

关于ios - MPMoviePlayerViewController观看后隐藏StatusBar并销毁Frame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22196565/

相关文章:

ios - 为什么 MPMoviePlayerController 在寻找 HTTP Live 流后报告错误的时间戳

ios - IB,保持 ImageView 居中,但随着屏幕尺寸增长,保持宽高比

ios - 如何使用 NSURLProtocol 模拟 AJAX 调用?

iphone - 在 iPhone 的 OpenGL ES 中请求深度缓冲区

objective-c - MPMoviePlayerController 不会设置为我声明的大小框架

ios - MPMoviePlayerController:Seek Button 点击​​卡住视频 - 黑屏

ios - 推送通知不起作用(仅在 Debug模式下有效)

ios - var private(set) 和 let 之间的区别?

ios - 如何使用 NSUserDefault 将选定的 TableViewCell 文本发送到之前的 ViewController

objective-c - iOS - 将菜单项添加到 Safari "Open with"