Search code examples
objective-ciphonecore-animationcore-graphics

Image getting pixelated when used as part of an animation in iPhone animation


After countless tries I got my animation animating right (Why oh why is the layer's coordinate system Y flipped from the view's coordinate system, I will never guess) but it seems that it degrades the image quality for some reason:

(green circled are examples of the original good quality images, the red circled is to emphasize the difference. original image.).

Close up:

alt text

(The lower images are as supposed to be, except the left one. The rest are pixelated.)

The code I'm using (approximately, you can see the exact one in the image.):

CGImageRef *ir = [UIImage imageNamed:@"something"].CGImage;
CALayer *cl = [CALayer layer];
cl.contents = ir;

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
anim.duration = 5;
anim.autoreverses = NO;
anim.removedOnCompletion = NO;

anim.fromValue = **something**
anim.toValue = **anotherthing**
[cl addAnimation:anim forKey: @"fallDown"];

My questions:

  1. Why is there such a difference between the images? How do I fix it?

  2. How is my code? I just can't find enough examples / explanations about the animation types and all stuff you can do with it (for example all of the animatable properties). And I am learning the SDK by myself (I have iPhone in Action but it's quite basic) and there is no one I know to review my code :)


Solution

  • A friend had a stroke of genius: my image files were huge. When I switched to using smaller files (resized) everything looked the same. I'm guessing there is some resizing issue here.

    Thanks RL... :)