我正在尝试制作一些最初模糊的东西,然后再重点关注.我猜想它可以正常工作,但是当动画完成时,它仍然有点模糊.我这样做错了吗?
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"];
解决方法
您的问题是动画停止并被自动删除,但过滤器伴随着最小的模糊.
@H_502_8@您想要做的是在动画完成时移除模糊滤镜.您需要向CABasicAnimation实例添加一个委托,并实现 – [id< CAAnimationDelegate> animationDidStop:finished:]方法.
@H_502_8@如果您在这种情况下让自己成为代理,那么应该相当简单,在将动画添加到图层之前添加此行:
blurAnimation.delegate = self;@H_502_8@而回调同样简单:
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag { [[self layer] setFilters:nil]; }