CABasicAnimation 禁用动画层内的任何触摸活动
- (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我弄清楚了,属性 fillMode 主要负责禁用动画对象中的触摸事件。如果您的动画需要处理触摸事件,请不要使用它。基本上,我使用的解决方法是删除 fillMode 属性,并在将动画添加到图层后手动设置动画的最后阶段
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
如果我没记错的话,隐藏的物体不会受到触摸。我不知道如果将不透明度设置为零是否适用,但尝试看看如果您将其设置为 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 setanim.toValue
.