Skip to content

Instantly share code, notes, and snippets.

@pkluz
Created September 6, 2012 08:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkluz/3653117 to your computer and use it in GitHub Desktop.
Save pkluz/3653117 to your computer and use it in GitHub Desktop.
Spinning UIImageView (Custom Activity Indicator)
// Depends. Entirely in Interface Builder it's not doable, but what you can do is grab an UIImageView and place it on your view. Style it any way you want by assigning an image to it. Then in code you do this (i.e. in you viewDidLoad of the controller (or later, if you want it re-used, in its own subclass)):
- (void)viewDidLoad
{
[super viewDidLoad];
// Create an animation that rotates something around its Z axis.
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
// M_PI_2 = 360 degree rotation.
animation.toValue = [NSNumber numberWithDouble:M_PI_2];
// Have it take half a second to complete a single rotation.
animation.duration = 0.5f;
// Make it cumulative with the previously applied transformations, otherwise once the 'toValue' is reached it'd be finished.
animation.cumulative = YES;
// Have it repeat more often than you can possibly ever witness personally.
animation.repeatCount = HUGE_VALF;
// Add the animation to your imageView.
[self.yourImageView.layer addAnimation:animation forKey:@"activityIndicatorAnimation"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment