From 4c6987b20ea21f6bea096218f871d55dc3497ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Sat, 18 Apr 2015 19:40:26 -0700 Subject: [PATCH] Apply some friction to pan drift MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the panning velocity is low enough, ignore the pan gesture to simulate friction on the device’s glass screen. --- platform/ios/MGLMapView.mm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index b73f2647d..0586f17ae 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -677,13 +677,22 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; else if (pan.state == UIGestureRecognizerStateEnded || pan.state == UIGestureRecognizerStateCancelled) { CGPoint velocity = [pan velocityInView:pan.view]; + if (sqrtf(velocity.x * velocity.x + velocity.y * velocity.y) < 100) + { + // Not enough velocity to overcome friction + velocity = CGPointZero; + } + CGFloat duration = UIScrollViewDecelerationRateNormal; - CGPoint offset = CGPointMake(velocity.x * duration / 4, velocity.y * duration / 4); - mbglMap->moveBy(offset.x, offset.y, secondsAsDuration(duration)); + if ( ! CGPointEqualToPoint(velocity, CGPointZero)) + { + CGPoint offset = CGPointMake(velocity.x * duration / 4, velocity.y * duration / 4); + mbglMap->moveBy(offset.x, offset.y, secondsAsDuration(duration)); + } mbglMap->setGestureInProgress(false); - if (duration) + if ( ! CGPointEqualToPoint(velocity, CGPointZero)) { self.animatingGesture = YES;