2

我的情况:我有一个UIButton动画,它CAKeyframeAnimation被声明为一个类别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"];

问题是在动画之后,按钮没有收到触摸。如果我删除动画一切正常。有谁知道我做错了什么?

谢谢

4

3 回答 3

4

您不应该使用 kCAFillModeForwards 和 removedOnCompletion = NO 将动画层粘贴在最终位置。这不适用于控件,并导致您注意到的行为。

相反,在将动画添加到其图层之前设置按钮的最终状态。

self.layer.transform = CGAffineTransformMakeScale(finalScaleX, finalScaleY);
[self.layer addAnimation:group forKey:@"scale"];
于 2012-10-28T09:52:14.297 回答
4

问题是动画只改变了按钮的呈现,但触摸目标仍然和以前一样。您应该在完成后删除动画并在按钮上设置变换或测试表示层。

在一篇博客文章中写了关于命中测试动画层的文章,其中更详细地解释了它。

于 2012-10-28T13:36:38.993 回答
2

self.layer.transform = CGAffineTransformMakeScale(finalScaleX, finalScaleY);您必须在动画结束时插入以下代码行。

于 2012-10-29T08:09:31.710 回答