ios - 如何在 iOS 中使用 CoreAnimation 为 CIFilter 设置动画?

标签 ios core-animation calayer core-image

我想使用 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 实现。

documentation说:

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/

相关文章:

iphone - 通过 AppStore 更新后如何测试对钥匙串(keychain)属性的访问?

ios - UIView 不会以编程方式移动

iOS动画对象回到原来的位置

ios - 改变 CALayer 的旋转变换为一个值而不改变层的缩放变换

cocoa-touch - UIView和CALayer是什么关系

ios - 做手势时将 anchor 放在屏幕中央

ios - 在 iOS 应用中打开 iCloud Drive

ios - UILabel 没有名为 'text' 的标签

objective-c - 如何在设置动画时更改 UIView block 动画的速度(或持续时间)?

cocoa - 如何以编程方式设置 NSView 的图层