moviePlayBackDidFinish和Transition的效果 [英] moviePlayBackDidFinish and Transition's effect
问题描述
我想知道如何添加过渡(在视频开始播放时淡入,在视频结束播放时淡出).
i would like to know how to add a transition ( fade in when the video is getting to start and fade out when the video is finished ).
您能帮他完成这个任务吗,我有点迷失了过渡,从来没有在/之前玩过它:
Could you please help him in this task, i'm kind of lost with transition, never play with it before /:
这是我的代码
- (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];
}
推荐答案
您可以在播放电影之前捕获UI的屏幕截图.
You could capture a screenshot of your UI right before playing the movie.
UIGraphicsBeginImageContext(view.frame.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshotOfView = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
然后添加MoviePlayer,然后在该图像的顶部添加图像作为UIImageView(例如[[UIApplication sharedApplication] keyWindow]).然后您将图像淡出.
Then you add your MoviePlayer and then you add the Image as UIImageView on top of that (eg [[UIApplication sharedApplication] keyWindow]). Then you fade the image out.
(我不知道您是否也可以从0-1开始对moviePlayer.view.alpha进行动画处理.)
(I don't know if you also could just animate the moviePlayer.view.alpha from 0-1).
可以通过设置Alpha值的动画来实现基本的淡入/淡出:
A basic fadein/fadeout can be achieved by animating the alpha value:
view.alpha = 0.0;
[UIView animateWithDuration: 0.35 animations:^{
view.alpha = 1.0;
}];
这篇关于moviePlayBackDidFinish和Transition的效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!