ios - UIButton 在 CAKeyframeAnimation 之后没有收到触摸

标签 ios uibutton core-animation cakeyframeanimation

我的情况: 我有一个 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"];

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

谢谢

最佳答案

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

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

self.layer.transform = CGAffineTransformMakeScale(finalScaleX, finalScaleY);
[self.layer addAnimation:group forKey:@"scale"];

关于ios - UIButton 在 CAKeyframeAnimation 之后没有收到触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13107690/

相关文章:

iphone - 如何使用 iCloud 在我的应用程序之间同步 .zip 文件?

ios - 收集有关用户在应用程序内点击位置的信息

ios - 如何添加实例变量并在自定义 UIButton 中使用它

swift - 存在后退按钮时无法设置 UINavigationBar 标题或将 UIButtons 放置在 UINavigationBar 中

iOS - 无法在具有比例变换的 UIViewAnimation 期间点击 UIView

ios - '位置管理器(_ :didRangeBeacons:inRegion: )' conflicts with optional requirement method ' locationManager(_:didRangeBeacons:inRegion:)' in protocol

ios - 代表正在重置为零

ios - 如何使用 switch 语句更改 UIButton 的图像?

ios - 使用 CoreAnimation 变形

ios - AVVideoCompositionCoreAnimationTool 中的 CALayer 实时模糊