• 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 18:20:45 +0200

Hello again,

in anticipation that the answer to my question might be to add UIImageViews as subviews rather than to draw UIImages from within the superview's drawRect:, I tried the following little test, which works like a charm. The question remains, though, whether this is the right/ best approach.

Wagner

The following code goes in the view controller managing the view where the images should be drawn into. It adds 25 image views to the view managed by the view controller, as a 5 x 5 grid, with a separation of 40 pixels between images. The grid rectangle has an origin at x = 30, y = 50. The time delay between images is 0.1 second, for a total animation time of 2.5 seconds.

- (void) viewDidLoad
{
    for (int i = 0; i < 5; ++i)
    {
        CGFloat x = 40*i + 30;
        for (int j = 0; j < 5; ++j)
        {
            CGFloat y = 40*j + 50;

            UIImageView* imgView = [[UIImageView alloc]
                initWithImage: [UIImage imageNamed: @"img.png"]];

            CGRect frame = imgView.frame;
            frame.origin.x = x - frame.size.width / 2.0;
            frame.origin.y = y - frame.size.height / 2.0;
            imgView.frame = frame;

            [self performSelector: @selector(addViewInSeparateThread:)
                       withObject: imgView
                       afterDelay: (5*j + i) / 10.0];

            [imgView release];
        }
    }
}

- (void) addViewInSeparateThread: (UIView*) imgView
{
    [self performSelectorOnMainThread: @selector(addViewInMainThread:)
                           withObject: imgView
                       waitUntilDone: YES];
}

- (void) addViewInMainThread: (UIView*) imgView
{
    [self.view addSubview: imgView];
}

_______________________________________________

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: CABasicAnimation causes crash on close/order out of window
  • Next by Date: Strange cast for CFURLRef
  • Previous by thread: How to animate the drawing of UIImages inside a drawRect: method of a UIView?
  • Next by thread: CABasicAnimation causes crash on close/order out of window
  • Index(es):
    • Date
    • Thread