Skip to content

Instantly share code, notes, and snippets.

@conradev
Created September 19, 2013 21:05
Show Gist options
  • Save conradev/6629819 to your computer and use it in GitHub Desktop.
Save conradev/6629819 to your computer and use it in GitHub Desktop.
CKSpinnerView - Emulating the app download spinner in the iOS 7 App Store
//
// CKSpinnerView.h
//
// Created by Conrad Kramer on 9/19/13.
// Copyright (c) 2013 Conrad Kramer. All rights reserved.
//
#import <CKShapeView/CKShapeView.h>
@interface CKSpinnerView : CKShapeView
@property (nonatomic, getter = isAnimating) BOOL animating;
@end
//
// CKSpinnerView.m
//
// Created by Conrad Kramer on 9/19/13.
// Copyright (c) 2013 Conrad Kramer. All rights reserved.
//
#import "CKSpinnerView.h"
static NSString * const CKSpinnerViewAnimationKey = @"spin";
@implementation CKSpinnerView
@dynamic animating;
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.animating = YES;
self.strokeStart = 0.075f;
self.lineWidth = 1;
self.fillColor = nil;
self.strokeColor = self.tintColor;
}
return self;
}
- (void)setAnimating:(BOOL)animating {
if (animating) {
CABasicAnimation *spin = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
spin.fromValue = @0.0f;
spin.toValue = @(2*M_PI);
spin.duration = 1.0f;
spin.repeatCount = HUGE_VALF;
[self.layer addAnimation:spin forKey:CKSpinnerViewAnimationKey];
} else {
[self.layer removeAnimationForKey:CKSpinnerViewAnimationKey];
}
}
- (BOOL)isAnimating {
return ([self.layer animationForKey:CKSpinnerViewAnimationKey] != nil);
}
- (void)layoutSubviews {
[super layoutSubviews];
CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
self.path = [UIBezierPath bezierPathWithArcCenter:center radius:13 startAngle:0 endAngle:2*M_PI clockwise:YES];
}
- (void)tintColorDidChange {
self.strokeColor = self.tintColor;
}
- (CGSize)intrinsicContentSize {
return CGSizeMake(26, 26);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment