• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to animate the drawing of UIImages inside a drawRect: method of a UIView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: How to animate the drawing of UIImages inside a drawRect: method of a UIView?
  • From: WT <email@hidden>
  • Date: Tue, 31 Mar 2009 17:10:33 +0200

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 (email@hidden)

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:
This email sent to email@hidden


  • Prev by Date: Thanks!
  • Next by Date: Re: NSTextField and clickable links
  • Previous by thread: Thanks!
  • Next by thread: How to animate the drawing of UIImages inside a drawRect: method of a UIView?
  • Index(es):
    • Date
    • Thread