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
Austin Gonzalez
2,377 PointsCrystal Ball animation code challenge task 3 of 3
Hey guys, Im struggling with the third part of this code challenge. The prompt is: Instruct your 'imageView' to start running the animation. So far I have this coded:
-
(void)viewDidLoad { [super viewDidLoad];
// backgroundImage is a local variable
UIImage *backgroundImage = [UIImage imageNamed:@"background"];
// imageView is a property
self.imageView = [[UIImageView alloc] initWithImage:backgroundImage];
// Add your code below! // Remember 'imageView' is a property // so refer to it as 'self.imageView'
self.imageView.animationImages = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"01.png"],
[UIImage imageNamed:@"02.png"],
[UIImage imageNamed:@"03.png"],nil];
self.imageView.animationDuration = 5;
- (void)startAnimating {
}
The problem is that I have no idea how to write a method to start running the animation because it wasn't mentioned in the video. Any help will be appreciated thanks.
1 Answer
Mike Bronner
16,395 PointsCheck out the instance methods listed in the SDK: https://developer.apple.com/library/ios/documentation/uikit/reference/UIImageView_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006889-CH3-DontLinkElementID_7
You'll find one there that is well-suited to start an animation sequence. :)
Austin Gonzalez
2,377 PointsAustin Gonzalez
2,377 PointsOk I get that - (void)startAnimating is what you meant. The problem is I don't know how to use it in conjunction with my code. I think I'm suppose to define the function in the .h file. But how do I implement it in the .m file to have instruct my imageView property to start running the animation.
Mike Bronner
16,395 PointsMike Bronner
16,395 PointsAh, I think I understand what you're looking for now.
You only need to define functions that you write in your .h file, not functions or methods that are already established. That's the case here: the method is already written and taken care of. All you need to do is call it:
[self.imageView startAnimating];Here's an article that shows an example implementation of the imageView animation sequence: http://www.appcoda.com/ios-programming-animation-uiimageview/. While it doesn't directly answer any questions you might have, it might highlight how it is used in the real world, outside of example-land, where things can get a bit abstract sometimes. :)
Austin Gonzalez
2,377 PointsAustin Gonzalez
2,377 PointsThanks for all your help it worked!
Mike Bronner
16,395 PointsMike Bronner
16,395 PointsExcellent! :)