Created
September 6, 2012 08:35
-
-
Save pkluz/3653117 to your computer and use it in GitHub Desktop.
Spinning UIImageView (Custom Activity Indicator)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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