How to animate the drawing of UIImages inside a
drawRect: method of a UIView?



Hello,

in the drawRect: method of one of my app's UIViews, I'm drawing a grid of images, one per grid point. The code below works great except, of course, that it ignores the animating argument. I would like to animate the drawing by drawing what appears to the user as one image at a time, with a short time delay between images. (Of course, I'm *always* drawing one image at a time with the code below, but you know what I mean).

Now, it's not clear to me how to accomplish the animation. If these were UIImageViews instead of images, I could animate their frame properties using the beginAnimations:context: and commitAnimations class methods of UIView. Is that the way to go? If so, won't that be expensive and slow, considering that I'll be laying out about 100 subviews? (there are 2 "interlocked" grids of 49 images each). If that's not the way to go, then how do I animate the drawing?

Thanks in advance.

Wagner

- (void) drawGridInRect: (CGRect) rect Animating: (BOOL) animating
{
CGFloat xmin = rect.origin.x;
CGFloat ymin = rect.origin.y;

for (int i = 0; i < kGridSize; ++i)
{
CGFloat x = xmin + i * deltaX;

for (int j = 0; j < kGridSize; ++j)
{
CGFloat y = ymin + j * deltaY;

UIImage* imageObj = ...; // the image is provided by an image server

CGFloat wo2 = imageObj.size.width / 2.0;
CGFloat ho2 = imageObj.size.height / 2.0;

[imageObj drawAtPoint: CGPointMake(x - wo2, y - ho2)];
}
}
}

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/maillists%40codeha.us

This email sent to maillists@xxxxxxxxx



Privacy