hello..
i am a newbie in cocoa programming..i am creating an application where i want to animate the path when one image is dragged to another to replace its position...below is the part of my code where i am trying to animate...
- (void)animateImage: (NSImageView*)in_pImage withFrame: (NSRect)inFrame
{
// Bounces the placard back to the center
CALayer *welcomeLayer = [in_pImage layer];
// Create a keyframe animation to follow a path back to the center
CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath"position"];
bounceAnimation.removedOnCompletion = NO;
CGFloat animationDuration = 0.25;//1.5;
// Create the path for the bounces
CGMutablePathRef thePath = CGPathCreateMutable();
CGFloat midX = inFrame.origin.x + inFrame.size.width/2;
CGFloat midY = inFrame.origin.y + inFrame.size.height/2;
// Start the path at the placard's current location
CGPathMoveToPoint(thePath, NULL, in_pImage.frame.origin.x, in_pImage.frame.origin.y);
CGPathAddLineToPoint(thePath, NULL, midX, midY);
bounceAnimation.path = thePath;
bounceAnimation.duration = animationDuration;
// Create a basic animation to restore the size of the placard
CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath"transform"];
transformAnimation.removedOnCompletion = YES;
transformAnimation.duration = animationDuration;
transformAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
// Create an animation group to combine the keyframe and basic animations
CAAnimationGroup *theGroup = [CAAnimationGroup animation];
// Set self as the delegate to allow for a callback to reenable user interaction
theGroup.delegate = self;
theGroup.duration = animationDuration;
theGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
theGroup.animations = [NSArray arrayWithObjects:bounceAnimation, transformAnimation, nil];
// Add the animation group to the layer
[welcomeLayer addAnimation:theGroup forKey"animatePlacardViewToCenter"];
// Set the placard view's center and transformation to the original values in preparation for the end of the animation
//in_pImage.center = CGPointMake(inFrame.origin.x + inFrame.size.width/2, inFrame.origin.y + inFrame.size.height/2);//self.center;
// in_pImage.transform = CGAffineTransformIdentity;
}
but this dint worked...it shows an error of "CAKeyFrameAnimation undeclared", "CABasicAnimation undeclared" ...
i hav also included the QUARTZCORE framework and also the header #import <QuartzCore/QuartzCore.h>
So anyone help me out for the same...
any help wld b appreciated...
thank you and regards..
SACHIN..
i am a newbie in cocoa programming..i am creating an application where i want to animate the path when one image is dragged to another to replace its position...below is the part of my code where i am trying to animate...
- (void)animateImage: (NSImageView*)in_pImage withFrame: (NSRect)inFrame
{
// Bounces the placard back to the center
CALayer *welcomeLayer = [in_pImage layer];
// Create a keyframe animation to follow a path back to the center
CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath"position"];
bounceAnimation.removedOnCompletion = NO;
CGFloat animationDuration = 0.25;//1.5;
// Create the path for the bounces
CGMutablePathRef thePath = CGPathCreateMutable();
CGFloat midX = inFrame.origin.x + inFrame.size.width/2;
CGFloat midY = inFrame.origin.y + inFrame.size.height/2;
// Start the path at the placard's current location
CGPathMoveToPoint(thePath, NULL, in_pImage.frame.origin.x, in_pImage.frame.origin.y);
CGPathAddLineToPoint(thePath, NULL, midX, midY);
bounceAnimation.path = thePath;
bounceAnimation.duration = animationDuration;
// Create a basic animation to restore the size of the placard
CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath"transform"];
transformAnimation.removedOnCompletion = YES;
transformAnimation.duration = animationDuration;
transformAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
// Create an animation group to combine the keyframe and basic animations
CAAnimationGroup *theGroup = [CAAnimationGroup animation];
// Set self as the delegate to allow for a callback to reenable user interaction
theGroup.delegate = self;
theGroup.duration = animationDuration;
theGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
theGroup.animations = [NSArray arrayWithObjects:bounceAnimation, transformAnimation, nil];
// Add the animation group to the layer
[welcomeLayer addAnimation:theGroup forKey"animatePlacardViewToCenter"];
// Set the placard view's center and transformation to the original values in preparation for the end of the animation
//in_pImage.center = CGPointMake(inFrame.origin.x + inFrame.size.width/2, inFrame.origin.y + inFrame.size.height/2);//self.center;
// in_pImage.transform = CGAffineTransformIdentity;
}
but this dint worked...it shows an error of "CAKeyFrameAnimation undeclared", "CABasicAnimation undeclared" ...
i hav also included the QUARTZCORE framework and also the header #import <QuartzCore/QuartzCore.h>
So anyone help me out for the same...
any help wld b appreciated...
thank you and regards..
SACHIN..