It is very easy to allow users to interact with views while animating using the options field of block based animation. But in my program I am using a CAKeyframeAnimation and I don’t see any properties to set user interaction enabled. Is there any way to do this?
Thanks,
EDIT: Here is the actual code:
- (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];
}
You are most likely touching the wrong place. When the layer animates on screen the value never changes so the view is actually positioned where it was from the beginning, not where it appears on screen.
I did a blog post a few month ago on how to hit test animating layers. It describes the exact thing that you are trying to do.
You will need to add the touch handling (or gesture recognizer) to the superview and do the hit-testing of the
presentationLayeryourself to determine if the user tapped where the view appeared on screen.