Animating a gaussian blur using core animation?

前端 未结 2 1149
鱼传尺愫
鱼传尺愫 2021-02-02 01:51

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 d

2条回答
  •  春和景丽
    2021-02-02 02:30

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

提交回复
热议问题