gpt4 book ai didi

iphone - 使用 CAAnimation 启用用户交互?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:50:35 24 4
gpt4 key购买 nike

允许用户在使用基于 block 的动画的选项字段进行动画处理时与 View 交互非常容易。但是在我的程序中,我使用的是 CAKeyframeAnimation 并且我没有看到任何属性来设置启用的用户交互。有什么办法吗?

谢谢,

编辑:这是实际的代码:

- (void)move
{
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 50, 120);
for (int i = 0; i < 5; i ++)
CGPathAddLineToPoint(path, NULL, arc4random() % 320, arc4random() % 480);
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
[animation setPath:path];
[animation setDuration:10];
CFRelease(path);
[self.layer addAnimation:animation forKey:@"move"];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self setAlpha:0];
}

最佳答案

您很可能摸错了地方。当图层在屏幕上显示动画时,该值永远不会改变,因此 View 实际上定位在它开始时的位置,而不是它出现在屏幕上的位置。

我几个月前在 how to hit test animating layers 上发表了一篇博文.它准确描述了您要尝试做的事情。

您需要将触摸处理(或手势识别器)添加到 super View ,并自行对 presentationLayer 进行点击测试,以确定用户是否点击了 View 在屏幕上出现的位置。

关于iphone - 使用 CAAnimation 启用用户交互?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11110485/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com