How to find out if a CAAnimation has ended
How to find out if a CAAnimation has ended
- Subject: How to find out if a CAAnimation has ended
- From: Benjámin Salánki <email@hidden>
- Date: Mon, 23 Feb 2009 07:05:22 +0100
Hi there,
I have an application which uses CAAnimation. It basically moves drops
(moves down the y axis) CALayers (in pairs which move independently
from each other) when a key is pressed. I need to be able to determine
when the animation has stopped to be able to proceed according to the
state of the CALayers (basically I need to remove some of them if a
given state for them is reached. If I don't use CABasicAnimation but
simply the setPosition: property the layer gets removed the instant
the animation would begin because the code does not wait for the
animation to end, lacking in visual feedback towards the user). I
tried setting the delegate method - (void)animationDidStop:
(CAAnimation *)anim finished:(BOOL)flag;
but since I need to wait for two animations to stop, this didn't
work at first, but then I tried adding a BOOL to my delegate and
setting it to true on the first animation end and then proceeding with
my code after the second time the delegate received the message which
resulted in the appropriate behavior except that right after the
animation is finished, it jumps back to the originating state for a
split second.
CABasicAnimation* bubble1DropAnimation = [CABasicAnimation animation];
bubble1DropAnimation.keyPath = @"position.y";
bubble1DropAnimation.fromValue = [NSNumber numberWithFloat:[[[self
currentPair] bubble1] position].y];
bubble1DropAnimation.toValue = [NSNumber numberWithFloat:[self
dropPositionForSFBubble:[[self currentPair] bubble1]].y];
bubble1DropAnimation.timingFunction = [CAMediaTimingFunction
functionWithName: kCAMediaTimingFunctionEaseInEaseOut];
bubble1DropAnimation.delegate = [[SFPairDropDelegate alloc] init];
bubble1DropAnimation.removedOnCompletion = NO;
[[[self currentPair] bubble1] addAnimation:bubble1DropAnimation
forKey:@"pairDrop"];
CABasicAnimation* bubble2DropAnimation = [CABasicAnimation animation];
bubble2DropAnimation.keyPath = @"position.y";
bubble2DropAnimation.fromValue = [NSNumber numberWithFloat:[[[self
currentPair] bubble2] position].y];
bubble2DropAnimation.toValue = [NSNumber numberWithFloat:[self
dropPositionForSFBubble:[[self currentPair] bubble2]].y];
bubble2DropAnimation.timingFunction = [CAMediaTimingFunction
functionWithName: kCAMediaTimingFunctionEaseInEaseOut];
bubble2DropAnimation.delegate = [[SFPairDropDelegate alloc] init];
bubble2DropAnimation.removedOnCompletion = NO;
[[[self currentPair] bubble2] addAnimation:bubble2DropAnimation
forKey:@"pairDrop"];
and in the delegate I do
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag;
{
if(flag)
{
if(!continues)
{
continues = YES;
}
else
{
[[[NSApp delegate] game] handleDrop];
}
}
}
any ideas what I might be missing or how to proceed on a different
path if this is a dead end?
thanks in advance,
Ben
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden