Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CALayer/CAAnimation doesn't animate




On Jan 14, 2008, at 6:07 PM, Bill Dudney wrote:

Hi Joachim,

You should not be manipulating the layer that the view creates for its self as a general rule.

True.

If you don't create it and set it, you shoudn't mess with it.





If you call [self setLayer:[CALayer layer]] right before you call [self setWantsLayer:YES] you should start to see behavior that more closely matches what you want/expect.

This is how you should always do it. Set the layer to your requested layer class, then enabled layers.


But, no, you won't see the behavior you expect.

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"frameOrigin"];

// Configure animation
anim.fromValue = [NSValue valueWithPoint:NSMakePoint (0, 0)];
anim.toValue = [NSValue valueWithPoint:NSMakePoint (100, 100)];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.duration = 2.0;
anim.delegate = self;


   // Add animation to layer; also triggers the animation
   [layer addAnimation:anim forKey:@"frameOrigin"];

oints 1 - frameOrigin isn't a property of CALayer. position is. You can only animate properties of a layer that exist, and that are marked as animatable in the CALayer class. conceptual doc does cover this. Perhaps you're confusing with the view frameOrigin method?


point 2 - you're using explicit animation and you're using the default fillMode (kCAFillModeRemoved). This causes the explicit animation to be removed when the animation is over. So you blink, and it's gone back to the start point.

BTW, I'm not sure you want an explicit animation in this case anyways.. you'd expect that the layer would keep its 100,100 location, wouldn't you? in that case you could just use implicit animation. If you really want the different timing function than the default you can change the implicit animation for the "frame" property.

point 3 is because you're using the wrong delegate method if you're using animationDidStop: this isn't a CALayer delegate method. animationDidStop:finished: is.





_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >CALayer/CAAnimation doesn't animate (From: Joachim <email@hidden>)
 >Re: CALayer/CAAnimation doesn't animate (From: Bill Dudney <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.