且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用核心动画动画高斯模糊?

更新时间:2022-12-25 15:13:11

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

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];
}