cj5
cj5

Reputation: 795

CABasicAnimation disabling any touch activity within animated layer

- (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?

Upvotes: 1

Views: 1257

Answers (2)

cj5
cj5

Reputation: 795

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"]];

Upvotes: 1

David Liu
David Liu

Reputation: 9601

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.

Upvotes: 0

Related Questions