[ios] Simplified MBXAnnotationView
Eliminated the center view in favor of applying a background color and border to the annotation view’s layer.
This commit is contained in:
committed by
Minh Nguyễn
parent
bb2f627b12
commit
288b71b671
@@ -1,7 +1,4 @@
|
||||
#import <Mapbox/Mapbox.h>
|
||||
|
||||
@interface MBXAnnotationView : MGLAnnotationView
|
||||
|
||||
@property (nonatomic) UIColor *centerColor;
|
||||
|
||||
@end
|
||||
|
||||
@@ -1,28 +1,16 @@
|
||||
#import "MBXAnnotationView.h"
|
||||
|
||||
@interface MBXAnnotationView ()
|
||||
|
||||
@property (nonatomic) UIView *centerView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MBXAnnotationView
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
if (!self.centerView) {
|
||||
self.backgroundColor = [UIColor blueColor];
|
||||
self.centerView = [[UIView alloc] initWithFrame:CGRectInset(self.bounds, 1.0, 1.0)];
|
||||
self.centerView.backgroundColor = self.centerColor;
|
||||
[self addSubview:self.centerView];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setCenterColor:(UIColor *)centerColor {
|
||||
if (![_centerColor isEqual:centerColor]) {
|
||||
_centerColor = centerColor;
|
||||
self.centerView.backgroundColor = centerColor;
|
||||
}
|
||||
|
||||
self.layer.borderColor = [UIColor blueColor].CGColor;
|
||||
self.layer.borderWidth = 1;
|
||||
self.layer.cornerRadius = 2;
|
||||
}
|
||||
|
||||
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
|
||||
|
||||
@@ -587,22 +587,20 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie
|
||||
{
|
||||
annotationView = [[MBXAnnotationView alloc] initWithReuseIdentifier:MBXViewControllerAnnotationViewReuseIdentifer];
|
||||
annotationView.frame = CGRectMake(0, 0, 10, 10);
|
||||
annotationView.centerColor = [UIColor whiteColor];
|
||||
|
||||
annotationView.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
// uncomment to make the annotation view draggable
|
||||
// also note that having two long press gesture recognizers on overlapping views (`self.view` & `annotationView`) will cause weird behaviour
|
||||
// comment out the pin dropping functionality in the handleLongPress: method in this class to make draggable annotation views play nice
|
||||
annotationView.draggable = YES;
|
||||
|
||||
|
||||
|
||||
// uncomment to force annotation view to maintain a constant size when the map is tilted
|
||||
// by default, annotation views will shrink and grow as the move towards and away from the
|
||||
// horizon. Relatedly, annotations backed by GL sprites ONLY scale with viewing distance currently.
|
||||
// annotationView.scalesWithViewingDistance = NO;
|
||||
|
||||
} else {
|
||||
// orange indicates that the annotation view was reused
|
||||
annotationView.centerColor = [UIColor orangeColor];
|
||||
annotationView.backgroundColor = [UIColor orangeColor];
|
||||
}
|
||||
return annotationView;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user