From 9d58685274f021de553795e67a853cc610f1f1a0 Mon Sep 17 00:00:00 2001 From: Whirlwind Date: Wed, 10 Aug 2016 00:56:18 +0800 Subject: [PATCH] Fix property override super class. It is danger! --- .../SVPulsingAnnotationView.h | 2 - .../SVPulsingAnnotationView.m | 43 ++----------------- 2 files changed, 4 insertions(+), 41 deletions(-) diff --git a/SVPulsingAnnotationView/SVPulsingAnnotationView.h b/SVPulsingAnnotationView/SVPulsingAnnotationView.h index 60e70f7..020741d 100644 --- a/SVPulsingAnnotationView/SVPulsingAnnotationView.h +++ b/SVPulsingAnnotationView/SVPulsingAnnotationView.h @@ -12,9 +12,7 @@ @property (nonatomic, strong) UIColor *annotationColor; // default is same as MKUserLocationView @property (nonatomic, strong) UIColor *outerColor; // default is white @property (nonatomic, strong) UIColor *pulseColor; // default is same as annotationColor -@property (nonatomic, strong) UIImage *image; // default is nil @property (nonatomic, strong) UIImage *headingImage; // default is nil -@property (nonatomic, strong) UIImageView *imageView; @property (nonatomic, readwrite) float outerDotAlpha; // default is 1 @property (nonatomic, readwrite) float pulseScaleFactor; // default is 5.3 diff --git a/SVPulsingAnnotationView/SVPulsingAnnotationView.m b/SVPulsingAnnotationView/SVPulsingAnnotationView.m index 638424b..a23cc68 100644 --- a/SVPulsingAnnotationView/SVPulsingAnnotationView.m +++ b/SVPulsingAnnotationView/SVPulsingAnnotationView.m @@ -24,16 +24,6 @@ @interface SVPulsingAnnotationView () @implementation SVPulsingAnnotationView -@synthesize annotation = _annotation; -@synthesize image = _image; - -+ (NSMutableDictionary*)cachedRingImages { - static NSMutableDictionary *cachedRingLayers = nil; - static dispatch_once_t oncePredicate; - dispatch_once(&oncePredicate, ^{ cachedRingLayers = [NSMutableDictionary new]; }); - return cachedRingLayers; -} - - (id)initWithAnnotation:(id)annotation reuseIdentifier:(NSString *)reuseIdentifier { if(self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]) { self.layer.anchorPoint = CGPointMake(0.5, 0.5); @@ -72,11 +62,6 @@ - (void)rebuildLayers { _pulseAnimationGroup = nil; - if(!self.image) { - [_imageView removeFromSuperview]; - _imageView = nil; - } - if (self.headingImage) { [self addSubview:self.headingImageView]; } @@ -87,14 +72,13 @@ - (void)rebuildLayers { [self.layer addSublayer:self.colorHaloLayer]; [self.layer addSublayer:self.outerDotLayer]; - - if(self.image) - [self addSubview:self.imageView]; - else + + if(!self.image) [self.layer addSublayer:self.colorDotLayer]; } - (void)willMoveToSuperview:(UIView *)superview { + [super willMoveToSuperview:superview]; if(superview) [self rebuildLayers]; @@ -122,7 +106,6 @@ - (void)setAnnotationColor:(UIColor *)annotationColor { } _annotationColor = annotationColor; - _imageView.tintColor = annotationColor; _headingImageView.tintColor = annotationColor; if(self.superview) @@ -144,21 +127,11 @@ - (void)setPulseAnimationDuration:(NSTimeInterval)pulseAnimationDuration { } - (void)setImage:(UIImage *)image { - _image = image; + [super setImage:image]; if (self.superview) { [self rebuildLayers]; } - - CGFloat imageWidth = ceil(image.size.width); - CGFloat imageHeight = ceil(image.size.height); - - self.imageView.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; - self.imageView.frame = CGRectMake(floor((self.bounds.size.width - imageWidth) * 0.5), - floor((self.bounds.size.height - imageHeight) * 0.5), - imageWidth, - imageHeight); - self.imageView.tintColor = self.annotationColor; } - (void)setHeadingImage:(UIImage *)image { @@ -219,14 +192,6 @@ - (CAAnimationGroup*)pulseAnimationGroup { #pragma mark - Graphics -- (UIImageView *)imageView { - if(!_imageView) { - _imageView = [[UIImageView alloc] initWithFrame:self.bounds]; - _imageView.contentMode = UIViewContentModeTopLeft; - } - return _imageView; -} - - (UIImageView *)headingImageView { if (!_headingImageView) { _headingImageView = [[UIImageView alloc] initWithFrame:self.bounds];