Apply some friction to pan drift

When the panning velocity is low enough, ignore the pan gesture to simulate friction on the device’s glass screen.
This commit is contained in:
Minh Nguyễn
2015-04-18 19:40:26 -07:00
parent 09c169d7d2
commit 4c6987b20e

View File

@@ -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;