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 /include | |
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 'include')
-rw-r--r-- | include/mbgl/ios/MGLCalloutView.h | 67 | ||||
-rw-r--r-- | include/mbgl/ios/MGLCalloutViewProtocol.h | 35 | ||||
-rw-r--r-- | include/mbgl/ios/MGLMapView.h | 10 | ||||
-rw-r--r-- | include/mbgl/ios/Mapbox.h | 2 |
4 files changed, 73 insertions, 41 deletions
diff --git a/include/mbgl/ios/MGLCalloutView.h b/include/mbgl/ios/MGLCalloutView.h new file mode 100644 index 0000000000..8e72ee9d68 --- /dev/null +++ b/include/mbgl/ios/MGLCalloutView.h @@ -0,0 +1,67 @@ +#import <Foundation/Foundation.h> + +#import "MGLTypes.h" + +NS_ASSUME_NONNULL_BEGIN + +@protocol MGLCalloutViewDelegate; +@protocol MGLAnnotation; + +/** + A protocol for a `UIView` subclass that displays information about a selected annotation near that annotation. + */ +@protocol MGLCalloutView <NSObject> + +/** + An object conforming to the `MGLAnnotation` protocol whose details this callout view displays. + */ +@property (nonatomic, strong) id <MGLAnnotation> representedObject; + +/** + A view that the user may tap to perform an action. This view is conventionally positioned on the left side of the callout view. + */ +@property (nonatomic, strong) UIView *leftAccessoryView; + +/** + A view that the user may tap to perform an action. This view is conventionally positioned on the right side of the callout view. + */ +@property (nonatomic, strong) UIView *rightAccessoryView; + +/** + An object conforming to the `MGLCalloutViewDelegate` method that receives messages related to the callout view’s interactive subviews. + */ +@property (nonatomic, weak) id<MGLCalloutViewDelegate> delegate; + +/** + Presents a callout view by adding it to `inView` and pointing at the given rect of `inView`’s bounds. Constrains the callout to the bounds of the given view. + */ +- (void)presentCalloutFromRect:(CGRect)rect inView:(UIView *)view constrainedToView:(UIView *)constrainedView animated:(BOOL)animated; + +/** + Dismisses the callout view. + */ +- (void)dismissCalloutAnimated:(BOOL)animated; + +@end + +/** + The MGLCalloutViewDelegate protocol defines a set of optional methods that you can use to receive messages from an object that conforms to the MGLCalloutView protocol. The callout view uses these methods to inform the delegate that the user has interacted with the the callout view. + */ +@protocol MGLCalloutViewDelegate <NSObject> + +@optional +/** + Returns a Boolean value indicating whether the entire callout view “highlights” when tapped. The default value is `YES`, which means the callout view highlights when tapped. + + The return value of this method is ignored unless the delegate also responds to the `-calloutViewTapped` method. + */ +- (BOOL)calloutViewShouldHighlight:(UIView<MGLCalloutView> *)calloutView; + +/** + Tells the delegate that the callout view has been tapped. + */ +- (void)calloutViewTapped:(UIView<MGLCalloutView> *)calloutView; + +@end + +NS_ASSUME_NONNULL_END
\ No newline at end of file diff --git a/include/mbgl/ios/MGLCalloutViewProtocol.h b/include/mbgl/ios/MGLCalloutViewProtocol.h deleted file mode 100644 index 590a298d71..0000000000 --- a/include/mbgl/ios/MGLCalloutViewProtocol.h +++ /dev/null @@ -1,35 +0,0 @@ -#import <Foundation/Foundation.h> - -#import "MGLTypes.h" - -NS_ASSUME_NONNULL_BEGIN - -@protocol MGLCalloutViewDelegate; - -@protocol MGLCalloutViewProtocol <NSObject> - -@property (nonatomic, copy) NSString *title, *subtitle; -@property (nonatomic, strong) UIView *leftAccessoryView, *rightAccessoryView; -@property (nonatomic, weak) id<MGLCalloutViewDelegate> delegate; - -// Presents a callout view by adding it to "inView" and pointing at the given rect of inView's bounds. -// Constrains the callout to the bounds of the given view. -- (void)presentCalloutFromRect:(CGRect)rect inView:(UIView *)view constrainedToView:(UIView *)constrainedView animated:(BOOL)animated; - -- (void)dismissCalloutAnimated:(BOOL)animated; - -@end - - -@protocol MGLCalloutViewDelegate <NSObject> - -@optional -// Controls whether the callout "highlights" when pressed. default YES. You must also respond to `-calloutViewClicked` below. -- (BOOL)calloutViewShouldHighlight:(UIView<MGLCalloutViewProtocol> *)calloutView; - -// Called when the callout view is clicked. -- (void)calloutViewClicked:(UIView<MGLCalloutViewProtocol> *)calloutView; - -@end - -NS_ASSUME_NONNULL_END
\ No newline at end of file diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h index 589e62a2f9..8a5ebef2a4 100644 --- a/include/mbgl/ios/MGLMapView.h +++ b/include/mbgl/ios/MGLMapView.h @@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol MGLMapViewDelegate; @protocol MGLAnnotation; @protocol MGLOverlay; -@protocol MGLCalloutViewProtocol; +@protocol MGLCalloutView; /** An interactive, customizable map view with an interface similar to the one @@ -963,15 +963,15 @@ IB_DESIGNABLE - (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id <MGLAnnotation>)annotation; /** - Returns a custom callout view to display for the specified annotation. + Returns a callout view to display for the specified annotation. - If the method is present in the delegate, it must return a new instance of a view dedicated to display the callout bubble. It will be configured by the map view. + If this method is present in the delegate, it must return a new instance of a view dedicated to display the callout bubble. It will be configured by the map view. If this method is not present, or if it returns `nil`, a standard, two-line, bubble-like callout view is displayed by default. @param mapView The map view that requested the callout view. @param annotation The object representing the annotation. - @return A view following the MGLCalloutView protocol. + @return A view conforming to the `MGLCalloutView` protocol, or `nil` to use the default callout view. */ -- (nullable UIView <MGLCalloutViewProtocol> *)mapView:(MGLMapView *)mapView customCalloutViewForAnnotation:(id <MGLAnnotation>)annotation; +- (nullable UIView <MGLCalloutView> *)mapView:(MGLMapView *)mapView calloutViewForAnnotation:(id <MGLAnnotation>)annotation; /** Returns the view to display on the left side of the standard callout bubble. diff --git a/include/mbgl/ios/Mapbox.h b/include/mbgl/ios/Mapbox.h index 70eebeeab4..fd4f532a40 100644 --- a/include/mbgl/ios/Mapbox.h +++ b/include/mbgl/ios/Mapbox.h @@ -1,7 +1,7 @@ #import "MGLAccountManager.h" #import "MGLAnnotation.h" #import "MGLAnnotationImage.h" -#import "MGLCalloutViewProtocol.h" +#import "MGLCalloutView.h" #import "MGLGeometry.h" #import "MGLMapCamera.h" #import "MGLMapView.h" |