Quote:
Originally Posted by truebluejw
Ok, so forgive me for asking a very very beginner question. I have watched and gone through most of the beginner and intermediate tutorials on this site and they have helped a lot. I've been playing around adding buttons, loading stuff, etc. I am confused on one thing though. I know how to load an image and set it up in imageview, but is there something I need to do to get an animated gif to play the frames? Should I be doing this with individual arrays? I just want to loop this one gif on part of the screen. It plays in the preview, but not in the actual emulator. I've read video doesn't play in the emulator sometimes? Thanks a bunch
|
hey there, to animate using a set of images, first place all the images in a folder and add it to your project. in the viewController.h add:
IBOutlet UIImageView *imageview;
and before the @ end, add:
- (IBAction) startAnimation;
in the viewController.m add the following code:
- (IBAction)animate

id)sender{
imageview.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"image1.png"],
[UIImage imageNamed:@"image2.png"],
[UIImage imageNamed:@"image3.png"],
[UIImage imageNamed:@"image4.png"],
[UIImage imageNamed:@"image5.png"],
[UIImage imageNamed:@"image6.png"],
[UIImage imageNamed:@"image7.png"],
[UIImage imageNamed:@"image8.png"], nil];
[imageview setAnimationRepeatCount:2]; /*how many times you want to repeat the animation*/
imageview.animationDuration = 1; /*set the number of seconds you want the animation to last*/
[imageview startAnimating];
}
Go to the viewController.xib, add an 'image view' to the 'view' then link the imageview from the file's owner to the image view. Second, add a button to the view and link the 'startAnimation' from the file's owner to the button in the view.
cheers.