简体   繁体   English

在iOS中使用筛选器进行CATransition

[英]CATransition with filter in iOS

I'm trying to set a filter to CATransition. 我正在尝试将过滤器设置为CATransition。 What seems to be so simple turned out problematic - it seems that the filter property is being ignored by CATransition and I'm left with the default fade effect (?!) 看起来如此简单的东西似乎是有问题的-似乎filter属性已被CATransition忽略,并且剩下默认的淡入淡出效果(?!)

UIImage *start = [UIImage imageNamed:@"start"];
UIImage *target = [UIImage imageNamed:@"target"];

CIImage *startImg = [CIImage imageWithCGImage:start.CGImage];
CIImage *endImg = [CIImage imageWithCGImage:target.CGImage];

CIFilter *filter = [CIFilter filterWithName:@"CICopyMachineTransition" keysAndValues:
                    @"inputImage" , startImg,
                    @"inputTargetImage" , endImg,
                    @"inputTime" , @1.0, nil];

CATransition *transition = [CATransition new];

transition.duration = 1.75;
transition.filter = filter;

[self.imageView.layer addAnimation:transition forKey:kCATransition];

self.imageView.image = target;

I ran into something similar and this post helped me out: 我遇到了类似的情况,这篇文章帮助了我:

Using transition CIFilters for CATransition 对CATransition使用过渡CIFilters

Basically, I was trying to use a filter combination that was unavailable on the IOS version I was running, but it took reading through that post to get me into the docs to figure it all out. 基本上,我试图使用我正在运行的IOS版本上不可用的过滤器组合,但是通读了这篇文章才使我进入文档以弄清一切。

Hope that gets you headed in the right direction. 希望您能朝正确的方向前进。

UPDATE: 更新:

Looking at this again, I wonder if your problem is here: 再看一遍,我想知道您的问题是否在这里:

CATransition *transition = [CATransition new];

Shouldn't you be calling the animation selector instead? 您不应该调用动画选择器吗?

CATransition *transition = [CATransition animation];

I'm not sure what 'new' does in this case or if it would initialize properly. 我不确定在这种情况下'new'是做什么的,或者它是否可以正确初始化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM