我想使用色度键(绿屏)全屏视频作为2个视图控制器之间的自定义转换。
视频开始完全绿色(=完全透明),显示一些动画效果(隐藏第一个视图控制器后面),并溶解回绿色(显示第二个视图控制器)。 Example transitions
我找出了色度键部分(使用GPUImage with a modified GPUImageChromaKeyFilter
)。
如何在后面切换视图控制器的同时将全屏视频显示为自定义转换?
答案 0 :(得分:0)
我不知道我可以在实施UIViews
的班级containerView
中向transitionContext
添加UIViewControllerAnimatedTransitioning
。
所以我在转换开始时将filterView
添加到容器中,并在完成块中再次将其删除。
@interface VideoTransitionAnimator() {
GPUImageOutput<GPUImageInput> *filter;
}
@property(nonatomic, strong) GPUImageMovie * movieFile;
@property(nonatomic, strong) GPUImagePicture * sourcePicture;
@end
@implementation VideoTransitionAnimator
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
{
return 2;
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
ViewController* fromViewController = (ViewController *) [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
[[transitionContext containerView] addSubview:toViewController.view];
toViewController.view.alpha = 0;
NSURL *sampleURL = [[NSBundle mainBundle] URLForResource:@"sample.m4v" withExtension:@"mp4"];
self.movieFile = [[GPUImageMovie alloc] initWithURL:sampleURL];
self.movieFile.shouldRepeat = NO;
filter = [[GPUImageChromaKeyTransparencyFilter alloc] init];
[(GPUImageChromaKeyTransparencyFilter *)filter setColorToReplaceRed:0.0 green:1.0 blue:0.0];
[(GPUImageChromaKeyTransparencyFilter *)filter setThresholdSensitivity:0.4];
[self.movieFile addTarget:filter];
GPUImageView *filterView = [[GPUImageView alloc] init];
filterView.frame = fromViewController.view.frame;
filterView.backgroundColor = [UIColor clearColor];
[filter addTarget:filterView];
UIView *containerView = [transitionContext containerView];
[containerView addSubview:filterView];
//rfilterView.fillMode = kGPUImageFillModeStretch;
[self.movieFile startProcessing];
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
toViewController.view.alpha = 1;
} completion:^(BOOL finished) {
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
[filterView removeFromSuperview];
}];
}
@end