问题
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 /:
here is my code
- (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];
}
回答1:
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();
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.
(I don't know if you also could just animate the moviePlayer.view.alpha from 0-1).
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;
}];
来源:https://stackoverflow.com/questions/9616628/movieplaybackdidfinish-and-transitions-effect