Here I got some workaround that helped work with my requirement. According to my need, I can get a single detection on both gadget marker markers, as well as in an empty area of โโthe map
I created a category for MGLMapView, (MGLMapView + EDCMapboxView) and overrides sensory methods
-touchesBegan:withEvent: -touchesMoved:withEvent: -touchesEnded:withEvent: -touchesCancelled:withEvent:
MGLMapView + EDCMapboxView.h
@protocol EDCMapboxViewDelegate <NSObject> @optional - (void)mapboxViewDidCreateNewTicket:(MGLMapView*)mapView; @end @interface MGLMapView (EDCMapboxView) @property (assign, nonatomic) BOOL shouldCreateNewTicket; @property (weak, nonatomic) id <EDCMapboxViewDelegate> mapboxDelegate; @end
MGLMapView + EDCMapboxView.m
@implementation MGLMapView (EDCMapboxView) @dynamic mapboxDelegate; #pragma mark -- Accessor - (BOOL)shouldCreateNewTicket { return [objc_getAssociatedObject(self, @selector(shouldCreateNewTicket)) boolValue]; } - (void)setShouldCreateNewTicket:(BOOL)flag { objc_setAssociatedObject(self, @selector(shouldCreateNewTicket), @(flag), OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -(id<EDCMapboxViewDelegate>)mapboxDelegate{ return objc_getAssociatedObject(self, @selector(mapboxDelegate)); } - (void)setMapboxDelegate:(id<EDCMapboxViewDelegate>)mapboxDelegate{ objc_setAssociatedObject(self, @selector(mapboxDelegate), mapboxDelegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } #pragma mark -- Overrided method for UIResponder - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{ NSLog(@"touchesBegan"); } - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{ NSLog(@"touchesMoved"); self.shouldCreateNewTicket = NO; } - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{ NSLog(@"touchesEnded"); } - (void)touchesCancelled:(nullable NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{ NSLog(@"touchesCancelled"); [self createNewTicket]; } - (void)createNewTicket{ if(self.shouldCreateNewTicket){ NSLog(@"Allowed to Create New ticket"); // Tells that tap is on empty area. if([self.mapboxDelegate respondsToSelector:@selector(mapboxViewDidCreateNewTicket:)]){ [self.mapboxDelegate mapboxViewDidCreateNewTicket:self]; } } else{ NSLog(@"Not allowed to create New ticket"); // Tells tap is on annotation marker. self.shouldCreateNewTicket = YES; } }
EDCMapboxViewController.m
- (void)viewDidLoad { [super viewDidLoad]; self.mapView.shouldCreateNewTicket = YES; ..... ....... ........ } - (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id <MGLAnnotation>)annotation { NSLog(@"annotationCanShowCallout"); // Tells that annotation is tapped, then do not allow to create ticket. self.mapView.shouldCreateNewTicket = NO; return YES; } - (void)mapboxViewDidCreateNewTicket:(MGLMapView*)mapView{ // Tells that tap is on empty area and not on marker, then allow to create ticket. }
It worked for me, hope it helps you and the guys. Thanks.