Re: Using Core Animation to animate view properties?
Re: Using Core Animation to animate view properties?
- Subject: Re: Using Core Animation to animate view properties?
- From: Matt Long <email@hidden>
- Date: Wed, 22 Oct 2008 10:54:21 -0600
Hey Jim,
I don't know much about NSAnimation as I haven't used it, however, I
can try to answer your three questions from a Core Animation standpoint.
1. If you want to know whether an animation is still running, just
check to see if it is still in the animations dictionary in the layer.
A call like this would do it:
if( [layer animationForKey:@"mykey"] != nil )
{
// animation is still running, so do something
}
I'm assuming you've set the key for your animation for @"mykey" when
you created the animation. The above call will not work if you have
set your removedOnCompletion field in the animation to NO, but the
default is YES.
2. To abort an animation, simply remove it from the animations
dictionary. A call like this would work:
[layer removeAnimationForKey:@"mykey"];
If you want to know after the fact whether the animation completed,
you can implement this delegate method on the animation:
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
If flag is set to false, then the animation was interrupted.
3. To "fast forward" to the target value after an abort, simply set
the value by calling set on the parameter explicitly. If it's opacity,
you are animating, for example. just call
[layer setOpacity:1.0];
How you apply this to view properties, I'm not sure, but this is how
you do these things with layers. Hope that helps.
-Matt
On Oct 20, 2008, at 7:36 PM, Jim Correia wrote:
I have some view properties for which I'd like to use Core Animation
to drive the animation.
In my old code, I used a subclass of NSAnimation which interpolated
the target value and set the property on the view via KVO. This
seems like a perfect use for CABasicAnimation and the animator proxy.
When using NSAnimation, if I needed to prematurely abort the
animation, I could send -stopAnimation to my NSAnimation subclass.
(I also had enough information at hand that it was trivial to fast
forward the animated property to its target value if that was
desirable.)
What mechanism do I have to
- know that a property animation is in progress
- abort it, if necessary
- fast forward it to the target value after abort, if desired
- Jim
_______________________________________________
_______________________________________________
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