Animating a gaussian blur using core animation?

巧了我就是萌 提交于 2019-12-02 19:37:39

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

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.

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;

And the callback is equally simple:

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

If you're looking for an optimized way to animate a blur then I recommend creating a single blurred image of your view and then fading the blurred image from alpha 0 to 1 over the top of your original view. Seems nice and fast in tests.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!