views:

133

answers:

2

I have a few UIButtons that I'd like to trigger short 5-10 frame animations when pressed in the middle of the screen along with other nonrelated stuffs. Can I just drop one UIImageView in IB and update it, somehow, programmatically? It doesn't need to be overly complex, I don't even mind if it's hard coded, for now since it's such a small project.

Thanks.

A: 

Yes. Create an IBOutlet to your UIImageView and you can update it from code. For example, use its image property to set the UIImage that should be displayed. Or you can add the image to your app's resources and associate it with the UIImageView in Interface Builder. Use .png files since the iPhone has been optimized for them.
Since a UIImageView is a UIView, all the usual Core Animation methods can be used.

gerry3
+2  A: 

Here's an example of the easiest way you do an animation with just a few frames is:

Declare an IBOutlet UIImageView *timerAnimation and link it to your UIIMageView in IB. Add some number of images to your resources, such as you see needed below. Then load the images into an array - see the code:

timerAnimation.animationImages = [NSArray arrayWithObjects:
   [UIImage imageNamed:@"timer00.png"],
   [UIImage imageNamed:@"timer01.png"],
   [UIImage imageNamed:@"timer02.png"],
   [UIImage imageNamed:@"timer03.png"],
   [UIImage imageNamed:@"timer04.png"],
   [UIImage imageNamed:@"timer05.png"],
   [UIImage imageNamed:@"timer06.png"],
   [UIImage imageNamed:@"timer07.png"],
   [UIImage imageNamed:@"timer08.png"],
   [UIImage imageNamed:@"timer09.png"],
   [UIImage imageNamed:@"timer10.png"],
   [UIImage imageNamed:@"timer11.png"],
   [UIImage imageNamed:@"timer12.png"],
   [UIImage imageNamed:@"timer13.png"],
   [UIImage imageNamed:@"timer14.png"],
   [UIImage imageNamed:@"timer15.png"],
   [UIImage imageNamed:@"timer16.png"],
   [UIImage imageNamed:@"timer17.png"],
   [UIImage imageNamed:@"timer18.png"],
   [UIImage imageNamed:@"timer19.png"],
   [UIImage imageNamed:@"timer20.png"],
   [UIImage imageNamed:@"timer21.png"],
   [UIImage imageNamed:@"timer22.png"],
   [UIImage imageNamed:@"timer23.png"],
   [UIImage imageNamed:@"timer24.png"],
   [UIImage imageNamed:@"timer25.png"],
   [UIImage imageNamed:@"timer26.png"],
   [UIImage imageNamed:@"timer27.png"],
   [UIImage imageNamed:@"timer28.png"],
   [UIImage imageNamed:@"timer29.png"],
   [UIImage imageNamed:@"timer30.png"],
   [UIImage imageNamed:@"timer31.png"],
   [UIImage imageNamed:@"timer32.png"],
   [UIImage imageNamed:@"timer33.png"],
   [UIImage imageNamed:@"timer34.png"],
   [UIImage imageNamed:@"timer35.png"],
  //      [UIImage imageNamed:@"timer36.png"], save last picture for "times up"
   nil];
timerAnimation.animationDuration = 5.0;
timerAnimation.animationRepeatCount = 1;
[timerAnimation startAnimating];

This will run your animation until you call [timerAnimation stopAnimating];

mahboudz
Yes yes yes yes! This was absolutely just what I needed. Not overly complex, and just simple enough to be easy to implement.
nullArray