summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@gmail.com>2018-05-24 01:01:20 -0400
committerGitHub <noreply@github.com>2018-05-24 01:01:20 -0400
commit0212fd385cd991ef37c0efe0c1210948fd4d36fc (patch)
treeefd8e048751f5ae639143b83b3cd893c54024575
parent5e65cb7812727b6c0625e4fbde538ddb5ff4ba13 (diff)
downloadqtlocation-mapboxgl-0212fd385cd991ef37c0efe0c1210948fd4d36fc.tar.gz
[ios] Provide custom hit test for callout views (#11939)
-rw-r--r--platform/ios/CHANGELOG.md1
-rwxr-xr-xplatform/ios/vendor/SMCalloutView/SMCalloutView.m38
2 files changed, 39 insertions, 0 deletions
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md
index f34b15face..7c8181a65a 100644
--- a/platform/ios/CHANGELOG.md
+++ b/platform/ios/CHANGELOG.md
@@ -18,6 +18,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Adjusted when and how the camera transition update and finish callbacks are called, fixing recursion bugs. ([#11614](https://github.com/mapbox/mapbox-gl-native/pull/11614))
* Improved application launch performance.
* Fixed an issue preventing nested key path expressions get parsed accordingly to the spec. ([#11959](https://github.com/mapbox/mapbox-gl-native/pull/11959))
+* Added custom `-hitTest:withEvent:` to `MGLSMCalloutView` to avoid registering taps in transparent areas of the standard annotation callout. ([#11939](https://github.com/mapbox/mapbox-gl-native/pull/11939))
## 4.0.1 - May 14, 2018
diff --git a/platform/ios/vendor/SMCalloutView/SMCalloutView.m b/platform/ios/vendor/SMCalloutView/SMCalloutView.m
index a0049a3e2d..7f987c3355 100755
--- a/platform/ios/vendor/SMCalloutView/SMCalloutView.m
+++ b/platform/ios/vendor/SMCalloutView/SMCalloutView.m
@@ -62,6 +62,26 @@ NSTimeInterval const kMGLSMCalloutViewRepositionDelayForUIScrollView = 1.0/3.0;
return self;
}
+- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
+ UIView *hitView = [super hitTest:point withEvent:event];
+
+ // If we tapped on our container (i.e. the UIButton), then ask the background
+ // view if the point is "inside". MGLSMCalloutMaskedBackgroundView provides a
+ // custom implementation that checks against the main callout and the down arrow.
+ // This avoids taps in "blank" space being detected
+
+ if (hitView == self.containerView) {
+ // Ideally we'd use the background mask to determine whether a tap point
+ // is valid, but that's overkill in this situation
+ CGPoint backgroundPoint = [self convertPoint:point toView:self.backgroundView];
+ if (![self.backgroundView pointInside:backgroundPoint withEvent:event]) {
+ return nil;
+ }
+ }
+
+ return hitView;
+}
+
- (BOOL)supportsHighlighting {
if (![self.delegate respondsToSelector:@selector(calloutViewClicked:)])
return NO;
@@ -738,6 +758,24 @@ static UIImage *blackArrowImage = nil, *whiteArrowImage = nil, *grayArrowImage =
return layer;
}
+- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
+
+ // Only interested in providing a custom pointInside for touches.
+ if (event.type != UIEventTypeTouches) {
+ return [super pointInside:point withEvent:event];
+ }
+
+ NSArray *views = @[self.containerView, self.arrowView];
+ for (UIView *view in views) {
+ CGPoint viewPoint = [self convertPoint:point toView:view];
+ if (CGRectContainsPoint(view.bounds, viewPoint)) {
+ return YES;
+ }
+ }
+
+ return NO;
+}
+
@end
@implementation MGLSMCalloutBackgroundView