How to use CAMediaTiming's beginTime?
How to use CAMediaTiming's beginTime?
- Subject: How to use CAMediaTiming's beginTime?
- From: Joachim <email@hidden>
- Date: Fri, 25 Jan 2008 12:01:22 +0100
This is a follow-up to http://lists.apple.com/archives/Cocoa-dev/2008/Jan/msg01182.html
.
I now have an animation that makes a pop while fading in. This works
great. It gets called implicitly for all my sublayers via the
[rootLayer addSublayer:layer] call, as the layer implements an
actionForKey: method that returns the CAAnimationGroup (see code
snippet at the end).
However, for all the layers that are added in one round, the
animations runs at the exact same time. I'd like to add a bit of
randomness by starting the animations slightly offset to each other.
So I've been experimenting with CAMediaTiming's timeOffset and
beginTime properties. But adding one of these messes the animation up.
If I set group.beginTime = CACurrentMediaTime () + 1.0; the layer
first appears right away (using the default animation, fading in over
0.25s, I guess), and 1 second after disappears and does the expected
animation.
If I set group.timeOffset = 1.0; the animation is just offset so that
it starts 1 second into the animation and "wraps around" and stops
after <groups.duration> seconds. After that the layer is simply
displayed.
- I guess the beginTime is the right way to go - I just need the layer
not to appear before the animation starts a bit later. Any ideas?
Initially setting the layer to hidden or opacity = 0, makes solves
that problem, but also makes the layer disapear again after the
animation, and I'd like to avoid forcing it to stay visible in the
animationDidStop:finished: delegate method (also makes the layer
flicker).
- Should I abandon the actionForKey: scenario and make the animation
happen by other means?
Joachim
- (id<CAAction>)actionForKey:(NSString *)key
{
if ([key isEqualToString:kCAOnOrderIn])
{
CABasicAnimation *alphaAnim = [CABasicAnimation
animationWithKeyPath:@"opacity"];
[snip]
CAKeyframeAnimation *sizeAnim = [CAKeyframeAnimation
animationWithKeyPath:@"transform.scale"];
[snip]
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = [NSArray arrayWithObjects:alphaAnim, sizeAnim,
nil];
group.duration = 1.0;
group.beginTime = CACurrentMediaTime () + 0.5;
//group.timeOffset = 0.5;
return group;
}
else
return nil;
}
_______________________________________________
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