【问题标题】:moviePlayBackDidFinish and Transition's effectmoviePlayBackDidFinish 和 Transition 的效果
【发布时间】:2012-03-25 21:00:11
【问题描述】:

我想知道如何添加过渡(视频开始时淡入,视频结束时淡出)。

你能帮他完成这个任务吗,我有点迷失了过渡,以前从来没有玩过/:

这是我的代码

- (void) startSlideShow
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] 
                                         pathForResource:@"2" ofType:@"mov"]];


    MPMoviePlayerController *moviePlayer = 
    [[MPMoviePlayerController alloc] initWithContentURL:url];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayer];
    moviePlayer.view.frame = CGRectMake(0, 0, 768, 1024);

    moviePlayer.controlStyle = MPMovieControlStyleDefault;
    moviePlayer.shouldAutoplay = YES;
    [self.view addSubview:moviePlayer.view];
    [moviePlayer setFullscreen:YES animated:YES];
   }


-(void)moviePlayBackDidFinish: (NSNotification*)notification
{ 
    MPMoviePlayerController *moviePlayer = [notification object];

    [[NSNotificationCenter defaultCenter] removeObserver:self      
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:moviePlayer];

    if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)])
    {
        // the transition should be around here... (fade out)
        [moviePlayer.view removeFromSuperview];
    }
    [moviePlayer release];

    [self checkResources];
}

【问题讨论】:

    标签: objective-c xcode mpmovieplayercontroller transition effect


    【解决方案1】:

    您可以在播放电影之前截取用户界面的屏幕截图。

    UIGraphicsBeginImageContext(view.frame.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *screenshotOfView = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    然后添加您的 MoviePlayer,然后将图像添加为 UIImageView(例如 [[UIApplication sharedApplication] keyWindow])。然后你淡出图像。

    (我不知道您是否也可以将moviePlayer.view.alpha从0-1设置为动画)。

    基本的淡入/淡出可以通过设置 alpha 值来实现:

    view.alpha = 0.0;
    [UIView animateWithDuration: 0.35 animations:^{
        view.alpha = 1.0;
    }];
    

    【讨论】:

    • 我不明白...我想要的是在视频/图像开始时应用淡入/淡出效果。谢谢你帮助我!
    • 基本的淡入/淡出可以通过设置 alpha 值来实现。我将编辑我的答案。
    猜你喜欢
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-25
    • 2012-08-29
    • 2011-09-07
    相关资源
    最近更新 更多