Created
March 22, 2013 19:07
-
-
Save mlaster/5223880 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#import "CustomAnnotationView.h" | |
#import <QuartzCore/QuartzCore.h> | |
@interface CustomAnnotationView() | |
- (CAAnimation *)rotationAnimation; | |
- (CAAnimation *)scaleAnimation; | |
@end | |
@implementation CustomAnnotationView | |
- (instancetype)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier { | |
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]; | |
if (self != nil) { | |
CGRect frame = self.frame; | |
frame.size.width = 32.0f; | |
frame.size.height = 32.0f; | |
self.frame = frame; | |
self.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:0.5f]; | |
self.layer.borderColor = [[UIColor blackColor] CGColor]; | |
self.layer.borderWidth = 1.0f; | |
[self.layer addAnimation:[self rotationAnimation] forKey:@"spin"]; | |
NSLog(@"self.frame: %@", NSStringFromCGRect(self.frame)); | |
} | |
return self; | |
} | |
- (void)awakeFromNib { | |
CAAnimationGroup *ag = nil; | |
[super awakeFromNib]; | |
ag = [CAAnimationGroup animation]; | |
ag.animations = @[[self rotationAnimation], [self scaleAnimation]]; | |
ag.duration = 2.0f; | |
ag.repeatCount = INFINITY; | |
ag.autoreverses = YES; | |
ag.removedOnCompletion = NO; | |
[self.layer addAnimation:ag forKey:@"ag"]; | |
// [self.layer addAnimation:[self scaleAnimation] forKey:@"scale"]; | |
// [self.layer addAnimation:[self rotationAnimation] forKey:@"spin"]; | |
self.label.text = @"label"; | |
} | |
- (void)prepareForReuse { | |
NSLog(@"%@ prepareForReuse", self); | |
[super prepareForReuse]; | |
} | |
- (CAAnimation *)rotationAnimation { | |
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform"]; | |
rotation.valueFunction = [CAValueFunction functionWithName:kCAValueFunctionRotateZ]; | |
rotation.fromValue = @0.0f; | |
rotation.toValue = @((CGFloat)M_PI * 2.0); | |
rotation.duration = 2.0f; | |
rotation.repeatCount = INFINITY; | |
rotation.removedOnCompletion = NO; | |
return rotation; | |
} | |
- (CAAnimation *)scaleAnimation { | |
CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform"]; | |
scale.valueFunction = [CAValueFunction functionWithName:kCAValueFunctionScale]; | |
scale.fromValue = @[@1.0f, @1.0f, @1.0f]; | |
scale.toValue = @[@2.0f, @2.0f, @2.0f]; | |
scale.duration = 2.0f; | |
scale.repeatCount = INFINITY; | |
scale.autoreverses = YES; | |
scale.removedOnCompletion = NO; | |
return scale; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment