Conceptually understanding Core Animation
Conceptually understanding Core Animation
- Subject: Conceptually understanding Core Animation
- From: Joachim <email@hidden>
- Date: Fri, 18 Jan 2008 12:01:41 +0100
I'm sorry for asking these basic questions, but I have a hard time
understanding some of the CoreAnimation concepts fully. This is a
follow-up on (http://www.cocoabuilder.com/archive/message/cocoa/2008/1/14/196457
).
Even after having read the CA Guide, I don't understand what "state" a
layer is left in after having animated it:
I have a root layer in my layer-hosting view. The root layer has
several sublayers being added and removed over time. I have chosen to
subclass CALayer for my sublayer instances in order to obtain a nice
encapsulation. I now simply call [myLayer appearAtPosition:pos] and
several other similar (and more complicated) methods. I also have a
few instance variables in my subclass although that can be achieved
without subclassing.
When I'm animating a sublayer, explicitly in my case, I'd expect the
layer's property after the animation to be that of the toValue. But it
isn't - even if I set the fillMode like below:
// Code from myLayer.m
CABasicAnimation *anim = [CABasicAnimation
animationWithKeyPath:@"position"];
anim.toValue = [NSValue valueWithPoint:endPos];
anim.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.duration = MyAnimationDurationFromPointToPoint
(startPos, endPos);
anim.fillMode = kCAFillModeForwards;
anim.removedOnCompletion = NO;
anim.delegate = self;
[self addAnimation:anim forKey:@"position"];
Even though the layer appears at endPos after the animation, the
layer's position property is still startPos. That doesn't make sense
to me. At all.
And if I then call [self.superlayer setNeedsDisplay] in the -
animationDidStop:finished: delegate method, the just animated layer
simply disappears). If I set the layer's position to endPos after
animation, the layer jumps to startPos and animates from startPos to
endPos using the default animation values (implicit animation, I guess).
- How do I get the layer to stay at the endPos after an explicit
animation?
- Am I "wrong" in using layers instead of views as my main visual
element class?
The user must be able to click on them and drag them around. Think
of a card game type of application.
If I don't set removedOnCompletion to NO, the layer goes back to
startPos after animation although, conceptually, we're just talking
about removing the animation - after it's done. This is where I don't
understand the concept, because I'd think that the animation is just
the WAY the layer goes from start to end. Once the layer has been
animated, and it's at its end position, the animation's role is over.
I think the documentation could do a better job of explaining these
issues.
Another thing that puzzles me with regards to the animation object is
that it doesn't go away from the layer even if I call [self
removeAllAnimations] in my animationDidStop:finished: delegate method.
Calling [self animationForKey:@"position"] after -removeAllAnimations
(or -animationForKey:@"position"), it still returns the animation
object.
I'm thinking of layers as lightweight views, in broad terms, but I
must be making some wrong assumptions in doing so.
Any enlightening will be highly appreciated.
Cheers,
Joachim
_______________________________________________
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