diff options
author | Jesse Bounds <jesse@rebounds.net> | 2016-06-01 17:36:07 -0700 |
---|---|---|
committer | Jesse Bounds <jesse@rebounds.net> | 2016-06-01 17:36:07 -0700 |
commit | d9c6181f347c3d6b3cfd4bca7c5ded0d6d93e63d (patch) | |
tree | cbe8e24f775a45dd722189bf79c3281b3ec3910b /platform/ios/src/MGLAnnotationContainerView.m | |
parent | ce98a7bee7709cd07e7f064215474903a90a0836 (diff) | |
download | qtlocation-mapboxgl-d9c6181f347c3d6b3cfd4bca7c5ded0d6d93e63d.tar.gz |
[ios] Add annotation container view (#5194)
Add a container view to hold annotations. This gets around a performance
issue with `UIView:addSubview:` where adding views is N^2. It helps
annotation views avoid cutting into callout views when the annotation
views are transformed to be "flat".
Diffstat (limited to 'platform/ios/src/MGLAnnotationContainerView.m')
-rw-r--r-- | platform/ios/src/MGLAnnotationContainerView.m | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/platform/ios/src/MGLAnnotationContainerView.m b/platform/ios/src/MGLAnnotationContainerView.m new file mode 100644 index 0000000000..cd9c990ef0 --- /dev/null +++ b/platform/ios/src/MGLAnnotationContainerView.m @@ -0,0 +1,38 @@ +#import "MGLAnnotationContainerView.h" +#import "MGLAnnotationView.h" + +@interface MGLAnnotationContainerView () + +@property (nonatomic) NS_MUTABLE_ARRAY_OF(MGLAnnotationView *) *annotationViews; + +@end + +@implementation MGLAnnotationContainerView + +- (instancetype)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) + { + _annotationViews = [NSMutableArray array]; + } + return self; +} + ++ (instancetype)annotationContainerViewWithAnnotationContainerView:(nonnull MGLAnnotationContainerView *)annotationContainerView +{ + MGLAnnotationContainerView *newAnnotationContainerView = [[MGLAnnotationContainerView alloc] initWithFrame:annotationContainerView.frame]; + [newAnnotationContainerView addSubviews:annotationContainerView.subviews]; + return newAnnotationContainerView; +} + +- (void)addSubviews:(NS_ARRAY_OF(MGLAnnotationView *) *)subviews +{ + for (MGLAnnotationView *view in subviews) + { + [self addSubview:view]; + [self.annotationViews addObject:view]; + } +} + +@end |