使用核心动画动画高斯模糊? [英] Animating a gaussian blur using core animation?

查看:221
本文介绍了使用核心动画动画高斯模糊?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图动画的东西,它最初是模糊的,然后它成为焦点。我想它的工作原理OK,但是当动画完成它仍然有点模糊。我做错了吗?

I'm trying to animate something where it's initially blurry then it comes into focus. I guess it works OK, but when the animation is done it's still a little blurry. Am I doing this wrong?

CABasicAnimation* blurAnimation = [CABasicAnimation animation];
CIFilter *blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[blurFilter setDefaults];
[blurFilter setValue:[NSNumber numberWithFloat:0.0] forKey:@"inputRadius"];
[blurFilter setName:@"blur"];
[[self layer] setFilters:[NSArray arrayWithObject:blurFilter]];

blurAnimation.keyPath = @"filters.blur.inputRadius";
blurAnimation.fromValue = [NSNumber numberWithFloat:10.0f];
blurAnimation.toValue = [NSNumber numberWithFloat:1.0];
blurAnimation.duration = 1.2;

[self.layer addAnimation:blurAnimation forKey:@"blurAnimation"];


推荐答案

您的问题是动画停止, ,但是滤波器仍然保持最小的模糊。

Your problem is that the animation stops and is automatically removed, but the filter lingers with the tiniest of blur applied.

您想要做的是在动画完成时删除模糊过滤器。您需要向 CABasicAnimation 实例添加一个委托,并实现 - [id animationDidStop:finished:] 方法。

What you want to do is to remove the blur filter when the animation completes. You need to add a delegate to the CABasicAnimation instance and implement the -[id<CAAnimationDelegate> animationDidStop:finished:] method.

如果你让 self 这种情况应该是相当简单,添加这一行之前添加动画到您的图层:

If you let self be the delegate in this case it should be fairly simple, add this line before adding the animation to your layer:

blurAnimation.delegate = self;

回调也很简单:

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
    [[self layer] setFilters:nil];
}

这篇关于使用核心动画动画高斯模糊?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆