Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Code Challenge: Image Based Animation, Task 4/4

Hi! I need help passing the Image Based Animation code challenge, task 4.

Here is my code that I am using:

UIImage *image = [UIImage imageNamed:@"robot.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

/* Write your code below this line */
[view insertSubview:imageView atIndex:0];

NSArray *robotImages = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"Robot1.png"],
[UIImage imageNamed:@"Robot2.png"], 
[UIImage imageNamed:@"Robot3.png"], 
[UIImage imageNamed:@"Robot4.png"], nil];

imageView.animationImages = robotImages;

imageView.animationDuration = 5.0;
imageView.animationRepeatCount = 1;

I have passed every task except the final one, when it needs me to instruct imageView to run the animation. How do I do this? I would have thought that

[view insertSubview:imageView atIndex:0];

would have done this. Any ideas?

14 Answers

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

@paul your answer is at the 8:50 minute mark in this video

J.T. Gralka
J.T. Gralka
20,126 Points

Hey Paul,

It looks like you've done all of the work to set up your animation, but remember that you need to actually tell your application that you want your animation to start. In addition to checking out the video tutorial for image based animations here on Treehouse, you might also check out this entry to the iOS Developer Library on Apple's iOS development site.

Good luck!

J.T.

J.T. Gralka
J.T. Gralka
20,126 Points

You have to keep watching until he gets to the point where we talks about the - (void) startAnimating method. :-)

Thanks @Amit and @J.T.!

@Amit The 8:50 mark shows the following code:

imageView.animationRepeatCount = 1;

I already have this in it, so why is it still giving me the error?

@Amit Now my existing code isn't working (it says that I need to create robotImages, even though I already have, as you can see in the original post).

Any ideas?

@Amit Never mind about that last post (simple typo).

@J.T. Ah, ok. Thanks for your help! Hopefully it works this time.

Yep, it worked. Thank you very much!

Allen Atha
PLUS
Allen Atha
Courses Plus Student 24,710 Points

Hello all,

I can't tell you how many times I've watched the video from 00:08:50 on, but I'm pulling out my hair trying to figure out why I can't call the right method that refers to imageView? I'm totally at a loss. Posted is my umpteenth try. I'm ready for help.

UIImage *image = [UIImage imageNamed:@"robot.png"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

/* Write your code below this line */ [view insertSubview:imageView atIndex:0];

NSArray *robotImages = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"Robot1"], [UIImage imageNamed:@"Robot2"], [UIImage imageNamed:@"Robot3"], [UIImage imageNamed:@"Robot4"], nil];

imageView.animationImages = robotImages;

imageView.animationDuration = 5.0; imageView.animationRepeatCount = 1;

-(void) robotImages { [imageView startAnimating]; }

it should be just [imageView startAnimating];

Allen Atha
PLUS
Allen Atha
Courses Plus Student 24,710 Points

@Dogancan I could have sworn that I tried that from the get, good grief...yup. Coding...ARGH!

-Cheers!

UIImage *image = [UIImage imageNamed:@"robot.png"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

[view insertSubview:imageView atIndex:0];

NSArray *robotImages = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"Robot1.png"], [UIImage imageNamed:@"Robot2.png"], [UIImage imageNamed:@"Robot3.png"], [UIImage imageNamed:@"Robot4.png"], nil];

imageView.animationImages = robotImages; imageView.animationDuration = 5.0; imageView.animationRepeatCount = 1;

[imageView startAnimating];

what is wrong???

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

Brad Izquierdo Your code looks right except you should remove this line:

[view insertSubview:imageView atIndex:0];

I got it, thanks Amit Bijlani !!