diff options
author | Fredrik Karlsson <bjorn.fredrik.karlsson@gmail.com> | 2017-01-09 17:24:07 +0100 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2017-01-11 15:48:08 -0800 |
commit | f1fc9bdfeb9ba107d27242ee4618228c204e98a3 (patch) | |
tree | b19ffb83b632cdb4d1b2539be8045c8b370d0293 /platform/ios/app | |
parent | 57644b2804a3d27ff19a58e0f3015d83264833ab (diff) | |
download | qtlocation-mapboxgl-f1fc9bdfeb9ba107d27242ee4618228c204e98a3.tar.gz |
[ios] Optional positioning and stickiness for callout view
Diffstat (limited to 'platform/ios/app')
-rw-r--r-- | platform/ios/app/MBXCustomCalloutView.h | 4 | ||||
-rw-r--r-- | platform/ios/app/MBXCustomCalloutView.m | 7 | ||||
-rw-r--r-- | platform/ios/app/MBXViewController.m | 33 |
3 files changed, 38 insertions, 6 deletions
diff --git a/platform/ios/app/MBXCustomCalloutView.h b/platform/ios/app/MBXCustomCalloutView.h index a61619b79f..961f2d7f6a 100644 --- a/platform/ios/app/MBXCustomCalloutView.h +++ b/platform/ios/app/MBXCustomCalloutView.h @@ -7,4 +7,8 @@ * callout title for demonstration purpose. */ @interface MBXCustomCalloutView : UIView <MGLCalloutView> + +@property (nonatomic, assign, getter=isAnchoredToAnnotation) BOOL anchoredToAnnotation; +@property (nonatomic, assign) BOOL dismissesAutomatically; + @end diff --git a/platform/ios/app/MBXCustomCalloutView.m b/platform/ios/app/MBXCustomCalloutView.m index 9edc00f6e9..e46b727d84 100644 --- a/platform/ios/app/MBXCustomCalloutView.m +++ b/platform/ios/app/MBXCustomCalloutView.m @@ -17,6 +17,8 @@ static CGFloat const tipWidth = 10.0; } @synthesize representedObject = _representedObject; +@synthesize anchoredToAnnotation = _anchoredToAnnotation; +@synthesize dismissesAutomatically = _dismissesAutomatically; @synthesize leftAccessoryView = _leftAccessoryView; @synthesize rightAccessoryView = _rightAccessoryView; @synthesize delegate = _delegate; @@ -66,6 +68,11 @@ static CGFloat const tipWidth = 10.0; } } +- (void)setCenter:(CGPoint)center { + center.y = center.y - CGRectGetMidY(self.bounds); + [super setCenter:center]; +} + - (void)dismissCalloutAnimated:(BOOL)animated { if (self.superview) diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 496c30efc9..13401997a0 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -89,6 +89,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @end @interface MBXCustomCalloutAnnotation : MGLPointAnnotation +@property (nonatomic, assign) BOOL anchoredToAnnotation; +@property (nonatomic, assign) BOOL dismissesAutomatically; @end @implementation MBXCustomCalloutAnnotation @@ -699,12 +701,28 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { { [self.mapView removeAnnotations:self.mapView.annotations]; - MBXCustomCalloutAnnotation *annotation = [[MBXCustomCalloutAnnotation alloc] init]; - annotation.coordinate = CLLocationCoordinate2DMake(48.8533940, 2.3775439); - annotation.title = @"Custom Callout"; - - [self.mapView addAnnotation:annotation]; - [self.mapView showAnnotations:@[annotation] animated:YES]; + MBXCustomCalloutAnnotation *firstAnnotation = [[MBXCustomCalloutAnnotation alloc] init]; + firstAnnotation.coordinate = CLLocationCoordinate2DMake(48.8533940, 2.3775439); + firstAnnotation.title = @"Open anchored to annotation"; + firstAnnotation.anchoredToAnnotation = YES; + firstAnnotation.dismissesAutomatically = NO; + + MBXCustomCalloutAnnotation *secondAnnotation = [[MBXCustomCalloutAnnotation alloc] init]; + secondAnnotation.coordinate = CLLocationCoordinate2DMake(48.8543940, 2.3775439); + secondAnnotation.title = @"Open not anchored to annotation"; + secondAnnotation.anchoredToAnnotation = NO; + secondAnnotation.dismissesAutomatically = NO; + + MBXCustomCalloutAnnotation *thirdAnnotation = [[MBXCustomCalloutAnnotation alloc] init]; + thirdAnnotation.coordinate = CLLocationCoordinate2DMake(48.8553940, 2.3775439); + thirdAnnotation.title = @"Dismisses automatically"; + thirdAnnotation.anchoredToAnnotation = YES; + thirdAnnotation.dismissesAutomatically = YES; + + NSArray *annotations = @[firstAnnotation, secondAnnotation, thirdAnnotation]; + [self.mapView addAnnotations:annotations]; + + [self.mapView showAnnotations:annotations animated:YES]; } - (void)styleWaterLayer @@ -1582,8 +1600,11 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { if ([annotation respondsToSelector:@selector(title)] && [annotation isKindOfClass:[MBXCustomCalloutAnnotation class]]) { + MBXCustomCalloutAnnotation *customAnnotation = (MBXCustomCalloutAnnotation *)annotation; MBXCustomCalloutView *calloutView = [[MBXCustomCalloutView alloc] init]; calloutView.representedObject = annotation; + calloutView.anchoredToAnnotation = customAnnotation.anchoredToAnnotation; + calloutView.dismissesAutomatically = customAnnotation.dismissesAutomatically; return calloutView; } return nil; |