[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.
This commit is contained in:
committed by
Minh Nguyễn
parent
b70fd7ae69
commit
11d99bd890
67
include/mbgl/ios/MGLCalloutView.h
Normal file
67
include/mbgl/ios/MGLCalloutView.h
Normal file
@@ -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
|
||||
@@ -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
|
||||
@@ -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.
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user