Search code examples
objective-ccore-animation

core animation error


I was messing around with Core Animation trying to get it to work, and I'm fairly sure I did everything right but when I tried to run my program Xcode threw up these bizarre errors at me:

Undefined symbols for architecture i386: "_OBJC_CLASS_$_CALayer", referenced from: objc-class-ref in ViewController.o "_OBJC_CLASS_$_CABasicAnimation", referenced from: objc-class-ref in ViewController.o ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status

I have no idea what any of that means. I imported the QuartzCore framework into the appropriate view controller, and here is the code I used for the animation:

UIImage *image01 = [UIImage imageNamed:@"image.png"];
imageView = [[UIImageView alloc] initWithImage:image01];
imageView.frame = CGRectMake(455, 150, 150, 150);

CALayer *imageLayer = [CALayer layer];
imageLayer.bounds = imageView.frame;
imageLayer.contents = imageView;
[view.layer addSublayer:imageLayer];

CGFloat imageXAtStart = imageLayer.position.x;
imageLayer.position = CGPointMake(335, 150);

CABasicAnimation *imageAnimation = [CABasicAnimation animationWithKeyPath:@"position.x"];
imageAnimation.fromValue = [NSNumber numberWithFloat:imageXAtStart];
imageAnimation.toValue = [NSNumber numberWithFloat:335];
imageAnimation.duration = 3;
imageAnimation.beginTime = 2;
[imageLayer addAnimation:imageAnimation forKey:@"position"];

If it matters, the animation is just supposed to move the image/layer from one x value to another.


Solution

  • This means you haven't linked your application to the framework which implements those classes.

    Mind that linking is not the same as importing. By importing the header files you let the compiler know that the classes exist. By linking to the framework you point the compiler the implementation of the classes themselves.

    Right click your Frameworks directory (or any directory) in Xcode and select Add existing framework. Now choose the appropriate framework and click Choose.

    PS: George is right, do something about your accept rate. You've asked five or so questions but haven't accepted one answer. If you continue like this, eventually nobody will want to answer your questions anymore.