视图控制器的顶部栏按钮不出现

发布于 2024-12-11 00:51:18 字数 3451 浏览 0 评论 0原文

我有以下内容:

我将视图控制器推入导航控制器,如下所示:

 moviePlayer = [[[CustomMoviePlayerViewController alloc] initWithPath:path2] autorelease];
    [self.navigationController pushViewController:moviePlayer animated:YES];
    self.navigationController.navigationBarHidden = YES;
    [moviePlayer readyPlayer];

并加载了顶部栏上没有按钮的视频。

输入图片此处描述

当我返回到上一个视图并再次尝试加载此视图后,它显示:

在此处输入图像描述

突然,完成按钮出现在顶部栏中。

我的问题是为什么它从第一次开始就没有出现,因为我没有更改代码。

这是压入堆栈的 viewController 的代码:

@implementation CustomMoviePlayerViewController

- (void) moviePlayerLoadStateChanged:(NSNotification*)notification 
{
    // Unless state is unknown, start playback
    if ([mp loadState] != MPMovieLoadStateUnknown)
    {
        // Remove observer
        [[NSNotificationCenter  defaultCenter] 
         removeObserver:self
         name:MPMoviePlayerLoadStateDidChangeNotification 
         object:nil];
        [[mp view] setFrame:CGRectMake(0, -20, 320, 400)];
        [mp setScalingMode:MPMovieScalingModeAspectFill];

        // Add movie player as subview
        [[self view] addSubview:[mp view]];   

        // Play the movie
        [mp play];
    }
}

- (void) moviePlayBackDidFinish:(NSNotification*)notification 
{    
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

    // Remove observer
    [[NSNotificationCenter  defaultCenter] 
     removeObserver:self
     name:MPMoviePlayerPlaybackDidFinishNotification 
     object:nil];

    [self.navigationController popViewControllerAnimated:YES];  
}

- (void) readyPlayer
{
    mp =  [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    if ([mp respondsToSelector:@selector(loadState)]) 
    {
        // Set movie player layout
        [mp setControlStyle:MPMovieControlStyleFullscreen];
        [mp setFullscreen:YES];

        // May help to reduce latency
        [mp prepareToPlay];

        // Register that the load state changed (movie is ready)
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePlayerLoadStateChanged:) 
                                                     name:MPMoviePlayerLoadStateDidChangeNotification 
                                                   object:nil];
    }  
    else
    {
        // Register to receive a notification when the movie is in memory and ready to play.
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePreloadDidFinish:) 
                                                     name:MPMoviePlayerContentPreloadDidFinishNotification 
                                                   object:nil];
    }

    // Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayBackDidFinish:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:nil];
}

谢谢!:)

I have the following:

I push a view controller into a navigationController like this:

 moviePlayer = [[[CustomMoviePlayerViewController alloc] initWithPath:path2] autorelease];
    [self.navigationController pushViewController:moviePlayer animated:YES];
    self.navigationController.navigationBarHidden = YES;
    [moviePlayer readyPlayer];

And is loaded up a video which has no button on the top bar.

enter image description here

After I comeback to the previous view and try again to load up this view, it shows this:

enter image description here

Suddenly the Done button appears in the top bar.

My question is why doesn't it appear from this first time, cause I'm not changing the code.

This is the code of the viewController pushed into the stack:

@implementation CustomMoviePlayerViewController

- (void) moviePlayerLoadStateChanged:(NSNotification*)notification 
{
    // Unless state is unknown, start playback
    if ([mp loadState] != MPMovieLoadStateUnknown)
    {
        // Remove observer
        [[NSNotificationCenter  defaultCenter] 
         removeObserver:self
         name:MPMoviePlayerLoadStateDidChangeNotification 
         object:nil];
        [[mp view] setFrame:CGRectMake(0, -20, 320, 400)];
        [mp setScalingMode:MPMovieScalingModeAspectFill];

        // Add movie player as subview
        [[self view] addSubview:[mp view]];   

        // Play the movie
        [mp play];
    }
}

- (void) moviePlayBackDidFinish:(NSNotification*)notification 
{    
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

    // Remove observer
    [[NSNotificationCenter  defaultCenter] 
     removeObserver:self
     name:MPMoviePlayerPlaybackDidFinishNotification 
     object:nil];

    [self.navigationController popViewControllerAnimated:YES];  
}

- (void) readyPlayer
{
    mp =  [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    if ([mp respondsToSelector:@selector(loadState)]) 
    {
        // Set movie player layout
        [mp setControlStyle:MPMovieControlStyleFullscreen];
        [mp setFullscreen:YES];

        // May help to reduce latency
        [mp prepareToPlay];

        // Register that the load state changed (movie is ready)
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePlayerLoadStateChanged:) 
                                                     name:MPMoviePlayerLoadStateDidChangeNotification 
                                                   object:nil];
    }  
    else
    {
        // Register to receive a notification when the movie is in memory and ready to play.
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePreloadDidFinish:) 
                                                     name:MPMoviePlayerContentPreloadDidFinishNotification 
                                                   object:nil];
    }

    // Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayBackDidFinish:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:nil];
}

Thank you!:)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文