Search code examples
iosuibuttoncore-animationcakeyframeanimation

UIButton doesn't receive touch after CAKeyframeAnimation


My situation: I've a UIButton that it's animate with a CAKeyframeAnimation that's declared as a category on UIView:

    CAKeyframeAnimation * scale =  [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
    scale.duration = duration;
    scale.beginTime = delay;
    scale.fillMode = kCAFillModeForwards;

    NSMutableArray * times = [[NSMutableArray alloc] init];

    scale.values = values;
    scale.timingFunctions = times;

    CAAnimationGroup * group = [CAAnimationGroup animation];
    [group setDelegate:self];
    [group setDuration:duration + delay];
    [group setFillMode:kCAFillModeForwards];
    [group setRemovedOnCompletion:NO];
    [group setAnimations:[NSArray arrayWithObject:scale]];

    [self.layer addAnimation:group forKey:@"scale"];

The problem is that after the animation, the button doesn't receive touch. If I remove the animation all works fine. Does anyone know what I'm doing wrong ?

Thanks


Solution

  • You must insert the following line of code self.layer.transform = CGAffineTransformMakeScale(finalScaleX, finalScaleY); when the animation is ended.