diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-01-06 15:13:39 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-01-06 23:43:07 -0800 |
commit | 11d99bd890ef2cbadc16beb7289dd818fa86c9df (patch) | |
tree | 6b7650c5675fdd0c3b0719e4262ffc4213b83843 /ios | |
parent | b70fd7ae6947e9d0c2f4b2a2d23069cedac5fa4a (diff) | |
download | qtlocation-mapboxgl-11d99bd890ef2cbadc16beb7289dd818fa86c9df.tar.gz |
[ios] Refined custom callout view support
Renamed MGLCalloutView to MGLCompactCalloutView and MGLCalloutViewProtocol to MGLCalloutView to avoid an awkward workaround for a Swift name collision. Replaced individual title and subtitle properties with a single representedObject property that lets you use custom annotation properties in the custom callout view. Overrode a problematic SMCalloutView method. Added lots more documentation.
Diffstat (limited to 'ios')
-rw-r--r-- | ios/app/MBXCustomCalloutView.h | 12 | ||||
-rw-r--r-- | ios/app/MBXCustomCalloutView.m | 21 | ||||
-rw-r--r-- | ios/app/MBXViewController.mm | 6 |
3 files changed, 24 insertions, 15 deletions
diff --git a/ios/app/MBXCustomCalloutView.h b/ios/app/MBXCustomCalloutView.h index 43dfac414c..7f0a61bae3 100644 --- a/ios/app/MBXCustomCalloutView.h +++ b/ios/app/MBXCustomCalloutView.h @@ -1,16 +1,10 @@ #import <UIKit/UIKit.h> -#import <mbgl/ios/MGLCalloutViewProtocol.h> +#import <mbgl/ios/MGLCalloutView.h> -/* +/** * Basic custom callout view to demonstrate how to * add your own on your app. Will only show the * callout title for demonstration purpose. */ - -@interface MBXCustomCalloutView : UIView <MGLCalloutViewProtocol> - -@property (nonatomic, copy) NSString *title, *subtitle; -@property (nonatomic, strong) UIView *leftAccessoryView, *rightAccessoryView; -@property (nonatomic, weak) id<MGLCalloutViewDelegate> delegate; - +@interface MBXCustomCalloutView : UIView <MGLCalloutView> @end diff --git a/ios/app/MBXCustomCalloutView.m b/ios/app/MBXCustomCalloutView.m index fa83dc6027..0bbb9d99ed 100644 --- a/ios/app/MBXCustomCalloutView.m +++ b/ios/app/MBXCustomCalloutView.m @@ -1,5 +1,7 @@ #import "MBXCustomCalloutView.h" +#import <mbgl/darwin/MGLAnnotation.h> + static CGFloat const tipHeight = 10.0; static CGFloat const tipWidth = 10.0; @@ -9,7 +11,17 @@ static CGFloat const tipWidth = 10.0; @end -@implementation MBXCustomCalloutView +@implementation MBXCustomCalloutView { + id <MGLAnnotation> _representedObject; + UIView *_leftAccessoryView; + UIView *_rightAccessoryView; + __weak id <MGLCalloutViewDelegate> _delegate; +} + +@synthesize representedObject = _representedObject; +@synthesize leftAccessoryView = _leftAccessoryView; +@synthesize rightAccessoryView = _rightAccessoryView; +@synthesize delegate = _delegate; - (instancetype)initWithFrame:(CGRect)frame { @@ -32,8 +44,11 @@ static CGFloat const tipWidth = 10.0; { [view addSubview:self]; // prepare title label - self.mainLabel.text = self.title; - [self.mainLabel sizeToFit]; + if ([self.representedObject respondsToSelector:@selector(title)]) + { + self.mainLabel.text = self.representedObject.title; + [self.mainLabel sizeToFit]; + } // prepare our frame CGFloat frameWidth = self.mainLabel.bounds.size.width; CGFloat frameHeight = self.mainLabel.bounds.size.height * 2.0; diff --git a/ios/app/MBXViewController.mm b/ios/app/MBXViewController.mm index e67003b391..57817d752b 100644 --- a/ios/app/MBXViewController.mm +++ b/ios/app/MBXViewController.mm @@ -153,7 +153,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = { @"Add 10,000 Points", @"Add Test Shapes", @"Start World Tour", - @"Add 1 custom Point", + @"Add Custom Callout Point", @"Remove Annotations", @"Toggle Custom Style Layer", nil]; @@ -599,13 +599,13 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = { }]; } -- (UIView<MGLCalloutViewProtocol> *)mapView:(__unused MGLMapView *)mapView customCalloutViewForAnnotation:(id<MGLAnnotation>)annotation +- (UIView<MGLCalloutView> *)mapView:(__unused MGLMapView *)mapView calloutViewForAnnotation:(id<MGLAnnotation>)annotation { if ([annotation respondsToSelector:@selector(title)] && [annotation.title isEqualToString:kCustomCalloutTitle]) { MBXCustomCalloutView *calloutView = [[MBXCustomCalloutView alloc] init]; - calloutView.title = annotation.title; + calloutView.representedObject = annotation; return calloutView; } return nil; |