CABasicAnimation 禁用动画层内的任何触摸活动

发布于 2024-10-03 23:44:42 字数 558 浏览 6 评论 0原文

- (void)fadeOutStuff
{
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
    anim.delegate = self;
    anim.duration = 0.25f;
    anim.removedOnCompletion = NO;
    anim.fillMode = kCAFillModeForwards;
    anim.fromValue = [NSNumber numberWithFloat:1.0f];
    anim.fromValue = [NSNumber numberWithFloat:0.0f];
    [self.searchList.layer addAnimation:anim forKey:@"animationOpacity"];
}

我有这段代码来简单地对对象进行动画进出,动画完成后,该图层不可触摸。动画过程是否将图层设置为级别/索引?我仍然可以触摸动画层后面的元素,但不能触摸动画层本身。我是否缺少设置?根据这段代码,我是否以错误的方式处理动画?

- (void)fadeOutStuff
{
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
    anim.delegate = self;
    anim.duration = 0.25f;
    anim.removedOnCompletion = NO;
    anim.fillMode = kCAFillModeForwards;
    anim.fromValue = [NSNumber numberWithFloat:1.0f];
    anim.fromValue = [NSNumber numberWithFloat:0.0f];
    [self.searchList.layer addAnimation:anim forKey:@"animationOpacity"];
}

I have this code to simply animate an object in and out, and after the animation is complete, the layer is not touchable. Is the animation process setting the layer down a level/index? I can still touch elements behind the animated layer, but not the animated layer itself. Am I missing a setting? Am I going about animation the wrong way, based on this code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏末 2024-10-10 23:44:42

我弄清楚了,属性 fillMode 主要负责禁用动画对象中的触摸事件。如果您的动画需要处理触摸事件,请不要使用它。基本上,我使用的解决方法是删除 fillMode 属性,并在将动画添加到图层后手动设置动画的最后阶段

[self.searchList.layer addAnimation:anim forKey:@"animationOpacity"];
[self.searchList.layer setValue:[NSNumber numberWithFloat:endingOpacityValue forKey:@"opacity"]];

I figure this out, and the property fillMode is mainly responsible for disabling touch events in animated objects. Do not use it if whatever you're animating needs to handle touch events. Basically, the workaround I used was removed the fillMode property, and set the final stage of the animation manually after adding the animation to the layer

[self.searchList.layer addAnimation:anim forKey:@"animationOpacity"];
[self.searchList.layer setValue:[NSNumber numberWithFloat:endingOpacityValue forKey:@"opacity"]];
美羊羊 2024-10-10 23:44:42

如果我没记错的话,隐藏的物体不会受到触摸。我不知道如果将不透明度设置为零是否适用,但尝试看看如果您将其设置为 0.01f 而不是一直设置为 0,会发生什么。

顺便说一句,我不知道这是否是一个拼写错误或不,但您设置了 anim.fromValue 两次,并且没有设置 anim.toValue

If I remember correctly, hidden objects won't receive touches. I don't know if the applies if it's just opacity set to zero, but try seeing what happens if you do it to just 0.01f instead of all the way to 0.

By the way, I don't know if it's a typo or not, but you set anim.fromValue twice, and you don't set anim.toValue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文