【问题标题】:How can I use a video as custom view controller transition in iOS?如何在 iOS 中使用视频作为自定义视图控制器转换?
【发布时间】:2015-11-09 15:33:06
【问题描述】:

我想使用色度键(绿屏)全屏视频作为 2 个视图控制器之间的自定义过渡。

视频开始时完全是绿色(= 完全透明),显示一些动画效果(将第一个视图控制器隐藏在后面),然后重新变为绿色(显示第二个视图控制器)。 Example transitions

我已经弄清楚了色度键部分(使用GPUImagewith a modified GPUImageChromaKeyFilter)。

如何将视频全屏显示为自定义过渡,同时切换后面的视图控制器?

【问题讨论】:

    标签: ios video uiviewcontroller gpuimage uiviewanimationtransition


    【解决方案1】:

    我不知道我可以在实现UIViewControllerAnimatedTransitioning 的类中将UIViews 添加到transitionContext 中的containerView

    所以我在过渡开始时将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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多