NachoSoto / NSBKeyframeAnimation

jQuery-like animations in CoreAnimation
MIT License
370 stars 47 forks source link

How can I add a delay before the animation starts? #8

Closed Ricardo1980 closed 10 years ago

Ricardo1980 commented 10 years ago

Hello! I'm using something like this: NSBKeyframeAnimation *animation2 = [NSBKeyframeAnimation animationWithKeyPath:@"transform.scale.y" duration:animationDuration startValue:0 endValue:1 function:NSBKeyframeAnimationFunctionEaseOutElastic];

to animate several views at once. My question is, how can I add a delay before the animation starts? I know UIView animation... has a method for that. Thanks a lot, very useful lib.

NachoSoto commented 10 years ago

Hi Ricardo,

You can set an initial delay by setting the beginTime property in the animation object. Like so:

const NSTimeInterval delay = 1.0f;
animation.beginTime = CACurrentMediaTime() + delay;
Ricardo1980 commented 10 years ago

Works perfectly! BTW, is there any easy way to launch a block when the animation (after the delay) is going to be started? I wanted to add a sound. Thanks.

NachoSoto commented 10 years ago

You can do so by implementing the delegate method.

Ricardo1980 commented 10 years ago

It works! Although this is strange, CAAnimationDelegate is not an actual protocol.