我想使用 CABasicAnimation
向层添加过滤器。我想为这个过滤器的一些属性设置动画。我从文档中读到 filters
属性是可动画的,但在同一文档中,似乎很难找到一种方法来做到这一点!
那么,如何使用 animationWithKeyPath 从 CABasicAnimation 引用单个过滤器属性?
[CABasicAnimation animationWithKeyPath:@"filters._FILTER_._PROPERTY_"];
这是一个完整的示例,只是为了向您展示我是如何尝试让它工作的:
//Define the filter
CIFilter *filterOne = [CIFilter filterWithName:@"CISepiaTone"];
[filterOne setDefaults];
//Attach it to the Layer
self.layer.filters = [NSArray arrayWithObject:filterOne];
//HERE THE PROBLEM ---------------------------------------
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"filters.???????.inputIntensity"];
//EOF HERE THE PROBLEM -----------------------------------
//Define the Animation settings
animation.delegate = self;
animation.fromValue = [NSNumber numberWithInt:0];
animation.toValue = [NSNumber numberWithInt:1];
animation.duration = 0.3;
...etcetc...
最佳答案
我认为图层过滤器属性在 iOS 中根本不起作用。最近在 Apple 网站上的 Apple Core Animation 论坛上对此进行了讨论,一位自称为“Rincewind”的 Apple 工程师发帖称,图层过滤器功能根本没有为 iOS 实现。
iOS Note: While the CALayer class in iOS exposes the filters property, Core Image is not available. Currently the filters available for this property are undefined.
据我所知,您只能通过直接调用它们并取回 CIImage 作为输出来使用 CI 过滤器。然后您必须通过代码使用 CIImage。
关于ios - 如何在 iOS 中使用 CoreAnimation 为 CIFilter 设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12959988/