Marc
Marc

Reputation:

Animation one image to the next

I have a flash file and need to reprogram for iPhone.

The design of the app is a navbar with start buttom and an image view below them. I have 46 PNL images that I want to show in succession after the start button is clicked. Each picture will stay on the screen for 5 seconds.

I tried to replicate a code that I got off of YouTube but it did not work.

For the viewcontroller.h I used the following code verbatim and was able to link images (I call them ac) to the image view and also to establish a link for the start button:

{
 IBOutlet UIImageView *ac;
}

-(IBAction)startclick:(id)sender;

For the viewcontroller.m I used the following concept but I received many syntax warnings:

NSarray 
List of 46 png files using @" notation for string
Last png followed by nil 
Then some notation for length that each image appears.

If someone could help me out with the viewcontroller.h and viewcontroller.m to command this sort of animation, it would be much appreciated.

Upvotes: 0

Views: 280

Answers (1)

Nathan de Vries
Nathan de Vries

Reputation: 15511

You should use UIImageView's animationImages property to do this, with your button calling startAnimating and/or stopAnimating:

UIImage *frame1 = [UIImage imageNamed:@"frame1.png"];
UIImage *frame2 = [UIImage imageNamed:@"frame2.png"];
UIImage *frame3 = [UIImage imageNamed:@"frame2.png"];
UIImage *frame4 = [UIImage imageNamed:@"frame2.png"];

uiImageView.animationImages = [[NSArray alloc] initWithObjects:frame1, frame2, frame3, frame4, nil];
uiImageView.animationDuration = 1.0 // defaults is number of animation images * 1/30th of a second
uiImageView.animationRepeatCount = 5; // default is 0, which repeats indefinitely
[uiImageView startAnimating];

// [uiImageView stopAnimating];

If you can't work out the syntax of Objective-C, you're going to struggle to do pretty much anything related to iPhone development.

Upvotes: 1

Related Questions