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

Sakina Burch
Sakina Burch
1,853 Points

animation

Everything in my app looks great but I can not get it to animate the 60 images. It stays on the first one CB00001. Any suggestions?

6 Answers

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Sakina,

I'd like to help you with this issue. If you would, please post the relevant code to help me find potential problems.

Thanks

Sakina Burch
Sakina Burch
1,853 Points

This is a piece of it. There are 60 images

NSURL *soundURL = [NSURL fileURLWithPath:soundPath]; AudioServicesCreateSystemSoundID(CFBridgingRetain(soundURL), &soundEffect);

self.crystalBall  = [[BMCrystallBall alloc] init];
self.backgroundImageView.animationImages = [[NSArray alloc] initWithObjects:
                                            [UIImage imageNamed:@"CB00001"],
                                            [UIImage imageNamed:@"CB00002"],
                                            [UIImage imageNamed:@"CB00003"],

.....

    [UIImage imageNamed:@"CB000059"],
                                            [UIImage imageNamed:@"CB000060"],nil];


self.backgroundImageView.animationDuration = 2.5f;
self.backgroundImageView.animationRepeatCount = 1;

}

  • (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.

pragma mark - Prediction

} -(void) makePrediction {

    [self.backgroundImageView startAnimating];
    self.predictionLabel.text = [self.crystalBall randomPrediction];
    AudioServicesPlaySystemSound(soundEffect);
Justin Horner
Justin Horner
Treehouse Guest Teacher

I'm not sure if this is a copy/paste artifact or the formatting of the post but I do notice a couple of issues with the code.

(void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.
pragma mark - Prediction
} -(void) makePrediction {
    [self.backgroundImageView startAnimating];
    self.predictionLabel.text = [self.crystalBall randomPrediction];
    AudioServicesPlaySystemSound(soundEffect);

If this is the case then 'pragma mark - Prediction' is inside the didReceiveMemoryWarning. Also, there's no ending bracket on the makePrediciton method. Can you confirm that your code looks like the following.

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Prediction

- (void) makePrediction {
    [self.backgroundImageView startAnimating];
    self.predictionLabel.text = [self.crystalBall randomPrediction];
}

Thanks.

Rashii Henry
Rashii Henry
16,433 Points

Make sure you check your code and its seems like you've already created your array with the images. You just can't figure out why its stuck. so..

The reason its not animating and you're not getting any errors is maybe because of one of these reasons:

1) you didn't name the images properly when you created the array. 2) If you did name them all correctly you didn't call these methods immediately afterwards you initialized the array:

self.backgroundImageView.animationDuration =2.5f; self.backgroundImageView.animationRepeatCount = 1;

the first line tells how quick you want it to animate through those images. (larger the number the slower.) the second line is self explanatory as it just tells you how many time to repeat.

Rashii Henry
Rashii Henry
16,433 Points

and also, wherever you have your button make sure you tell the imageView to start animating by saying.

[self.backgroundImageView startAnimating];

Sakina Burch
Sakina Burch
1,853 Points

Thank you both for responding. I do have the start animating line of code, and the duration times work. It is just reading only the first image. Do in need the .png? added to the filename?

Justin Horner
Justin Horner
Treehouse Guest Teacher

You're welcome! The extension is not necessary in this case. I'm looking at the code you have provided now. Thank you for posting it.

Sakina Burch
Sakina Burch
1,853 Points

[self.backgroundImageView startAnimating]; is under the prediction pragma mark is this correct?

Justin Horner
Justin Horner
Treehouse Guest Teacher

Yes. As long as your code looks similar like this.

#pragma mark - Prediction
- (void) makePrediction()
{
    [self.backgroundImageView startAnimating];
    self.predictionLabel.text = [self.crystalBall randomPrediction];
}

Where the makePrediction method is under the pragmamark.

Sakina Burch
Sakina Burch
1,853 Points

Ok I moved the curly Brace up above

pragma Mark -Prediction it was inside the didRecieveMemoryWarning Braces. That was one fix but still don't see any images except the first on in the animation. It seems to be animating but no pic rotation. I am going to delete all the pics and try the steps again.

Rashii Henry
Rashii Henry
16,433 Points

when you press the button does the prediction show a random prediction and just not animate?

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Another suggestion would be to make sure that your connection between the storyboard and backgroundImageView are properly connected. Maybe try debugging the makePrediction method and make sure that the backgroundImaveView property is not nil.

I'm pretty sure this isn't the problem since you are seeing the image change to the first image in the animation but it's worth checking at this point.