【问题标题】:MPMoviePlayerViewController hides StatusBar and destroys Frame after watchingMPMoviePlayerController 观看后隐藏状态栏并销毁Frame
【发布时间】:2014-03-05 11:35:26
【问题描述】:

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

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 应该动画到全屏并开始播放,当视频完成时它应该去返回预览视图。到目前为止一切正常,但我有两个问题:

第一个问题: 每次我打开视图时,我的状态栏都会隐藏起来,看起来像这样:

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

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

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

第二个问题:

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

【问题讨论】:

    标签: ios objective-c mpmovieplayercontroller statusbar


    【解决方案1】:

    好的,我找到了解决这个问题的方法,它有点老套,但我没有找到其他解决方案。在我的 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;
    }
    

    【讨论】:

    • 我喜欢这种解决方案。从用户的角度来看,它们完成了工作并且看起来很棒。代码不好看也没关系。
    猜你喜欢
    • 2011-04-08
    • 1970-01-01
    • 1970-01-01
    • 2016-11-02
    • 1970-01-01
    • 2011-04-29
    相关资源
    最近更新 更多