CAKeyFrameAnimation undeclared

Discussion in 'Mac Programming' started by sachin.singh, Jan 14, 2009.

  1. sachin.singh macrumors newbie

    Joined:
    Oct 19, 2008
    #1
    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:mad:"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:mad:"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:mad:"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..:apple:
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
  3. sachin.singh thread starter macrumors newbie

    Joined:
    Oct 19, 2008
    #3
    hey kainjow...:)

    thanks for replying...newys i got the solution...i created a fresh new project and copied my entire code...it worked..!!! donno how..?? but i thnk i dint selected cocoa application while creating new project...

    My OS version is 10.5.4 and XCODE version is 3.1.1


    But now i am facing problem to animate the path .i.e. i am not able to set the center of NSImageView as "center" and "transform" property is unavailable for NSImageView...

    CGPathMoveToPoint(thePath, NULL, NSImageView.center , NSImageView.center);

    So plz help me out to animate the path...

    Thanks and Regards,
    Sachin...:apple:
     

Share This Page