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


Ryan Stevenson
Ryan Stevenson
1,799 Points

Animation in iOS

Hi, I am trying to animate a star by getting it to fade in and out. I have created the property as below in my .h file:

@property (weak, nonatomic) IBOutlet UIImageView *spinningStar;

I have then the following in my .m file but no animation Please could someone help?

import "LoginViewController.h"

@interface LoginViewController ()


@implementation LoginViewController

  • (void)viewDidLoad { [super viewDidLoad];

    self.spinningStar.animationImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"STAR100"], [UIImage imageNamed:@"STAR095"], [UIImage imageNamed:@"STAR090"], [UIImage imageNamed:@"STAR085"], [UIImage imageNamed:@"STAR080"], [UIImage imageNamed:@"STAR075"], [UIImage imageNamed:@"STAR070"], [UIImage imageNamed:@"STAR065"], [UIImage imageNamed:@"STAR060"], [UIImage imageNamed:@"STAR055"], [UIImage imageNamed:@"STAR050"], [UIImage imageNamed:@"STAR045"], [UIImage imageNamed:@"STAR040"], [UIImage imageNamed:@"STAR035"], [UIImage imageNamed:@"STAR030"], [UIImage imageNamed:@"STAR025"], [UIImage imageNamed:@"STAR020"], [UIImage imageNamed:@"STAR015"], [UIImage imageNamed:@"STAR010"], [UIImage imageNamed:@"STAR005"], [UIImage imageNamed:@"STAR000"],nil];

    self.spinningStar.animationDuration = 1; [self.spinningStar startAnimating]; }


Thanks Ryann

5 Answers

You would need to start the animation wouldn't you?

[self."Insert view here" startAnimating];

Just a guess....

Ryan Stevenson
Ryan Stevenson
1,799 Points

Hi Dylan, That's on my last line of code. It should make the animation start, however it doesn't seem to work. It doesn't even animate once! Becoming very stressful.

Oh yes I see it now. Just double check that your image names are the same as what are in your code. In the crystal ball app, my animation didn't work and it was because I had missed out a zero in the first image in my code. Once I fixed that it worked fine.

Otherwise you might have to wait for someone a bit more experienced haha

Also, is it a requirement to put the animation repeat count?

self.spinningStar.animationRepeatCount = 1;

Ryan Stevenson
Ryan Stevenson
1,799 Points

I've tried with the repeat count but nothing. If you leave the statement out then it will infinitely loop through. I've looked online but nothing seems to give a straightforward answer