1
- (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"];
}

我有这段代码可以简单地为对象设置动画,动画完成后,图层不可触摸。动画过程是否将图层设置为级别/索引?我仍然可以触摸动画层后面的元素,但不能触摸动画层本身。我错过了一个设置吗?基于此代码,我是否以错误的方式制作动画?

4

2 回答 2

1

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

[self.searchList.layer addAnimation:anim forKey:@"animationOpacity"];
[self.searchList.layer setValue:[NSNumber numberWithFloat:endingOpacityValue forKey:@"opacity"]];
于 2010-11-23T18:33:14.653 回答
0

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.

于 2010-11-20T02:32:49.873 回答