Search code examples
iosuiviewcore-animation

Achieving crisp zoom animation on a view


I was wondering how people achieve a zoom animation of a UIView that is crisp. I notice in sample code on the web,

self.frame = CGRectMake(0.0f, 0.0f, 200.0f, 150.0f);
[UIView beginAnimations:@"Zoom" context:NULL];
[UIView setAnimationDuration:0.5];
self.frame = CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f);
[UIView commitAnimations];

Basically just changing the frame. If I do this on an image that's 100 x 100, then the image does not look crisp. I was wondering if there's a way to make a UIView crisp with zooming. When I looked at the cocos2d transitions, the scene transitions for zooming don't seem to have any artifacts. Everything just looks crisp! I was wondering if that's because the UIView is already that size and they start out the view at the smaller size so when it zooms to the larger size it doesn't receive unwanted artifacts. Or if there's something they do in opengl or something that makes it look crisp. (I do not know opengl so if that question is totally wrong I apologize!) Thanks.


Solution

  • I think your code looks fine (though, I think the recommended way to animate is now UIView animate...). I think there might be two problems:

    1. You image is 100 x 100 and being blown up to full screen. This is never going to look good. (as discussed further in this answer).

    2. Your ratio is not preserved (1x1 image in a 2x1.5 frame).

    It is also worth thinking about what the initial size you draw the image at. If you have a 1000x1000 image, drawing it at 500x500 and then scaling it by two is not going to look as good as if you first draw it at 1000x1000, scale it down to 500x500 and then scale it back up. Although, the UIImageView property UIViewContentModeRedraw might be of help here.