add allowScrollGesturesDuringRotateOrZoom
This commit is contained in:
Jukka Hietanen
2021-04-06 21:49:38 +03:00
committed by GitHub
parent ee94520bff
commit a231fcbdeb
2 changed files with 28 additions and 0 deletions

View File

@@ -733,6 +733,12 @@ MGL_EXPORT
*/
@property(nonatomic, getter=isPitchEnabled) BOOL pitchEnabled;
/**
A Boolean value that determines whether gestures are anchored to the center coordinate of the map while rotating or zooming.
Default value is set to NO.
*/
@property(nonatomic) BOOL anchorRotateOrZoomGesturesToCenterCoordinate;
/**
A Boolean value that determines whether the user will receive haptic feedback
for certain interactions with the map.

View File

@@ -581,6 +581,9 @@ public:
// setup interaction
//
self.anchorRotateOrZoomGesturesToCenterCoordinate = NO;
_pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
_pan.delegate = self;
_pan.maximumNumberOfTouches = 1;
@@ -1829,6 +1832,11 @@ public:
[self cancelTransitions];
CGPoint centerPoint = [self anchorPointForGesture:pinch];
if (self.anchorRotateOrZoomGesturesToCenterCoordinate) {
if (pinch.numberOfTouches != 1 || pinch.state == UIGestureRecognizerStateEnded) {
centerPoint = [self contentCenter];
}
}
MGLMapCamera *oldCamera = self.camera;
self.cameraChangeReasonBitmask |= MGLCameraChangeReasonGesturePinch;
@@ -1937,6 +1945,9 @@ public:
[self cancelTransitions];
CGPoint centerPoint = [self anchorPointForGesture:rotate];
if (self.anchorRotateOrZoomGesturesToCenterCoordinate) {
centerPoint = [self contentCenter];
}
MGLMapCamera *oldCamera = self.camera;
self.cameraChangeReasonBitmask |= MGLCameraChangeReasonGestureRotate;
@@ -1947,6 +1958,9 @@ public:
// Check whether a zoom triggered by a pinch gesture is occurring and if the rotation threshold has been met.
if (MGLDegreesFromRadians(self.rotationBeforeThresholdMet) < self.rotationThresholdWhileZooming && self.isZooming && !self.isRotating) {
self.rotationBeforeThresholdMet += fabs(rotate.rotation);
if (self.anchorRotateOrZoomGesturesToCenterCoordinate) {
self.rotationBeforeThresholdMet = 0;
}
rotate.rotation = 0;
return;
}
@@ -2472,6 +2486,14 @@ public:
}
}
}
else if (gestureRecognizer == _pan)
{
if (self.anchorRotateOrZoomGesturesToCenterCoordinate) {
if (self.isZooming || self.isRotating) {
return NO;
}
}
}
return YES;
}