Skip to content

Commit

Permalink
refs route-me#181: move drags according to gesture offset in layer
Browse files Browse the repository at this point in the history
  • Loading branch information
incanus committed Nov 19, 2013
1 parent 54364ae commit 073cd46
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion MapView/Map/RMMapView.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ @implementation RMMapView
BOOL _draggingEnabled, _bouncingEnabled;

RMAnnotation *_draggedAnnotation;
CGPoint _dragOffset;

CLLocationManager *_locationManager;

Expand Down Expand Up @@ -1777,6 +1778,10 @@ - (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer
//
_draggedAnnotation = [((RMMapLayer *)hit) annotation];

// remember where in the layer the gesture occurred
//
_dragOffset = [_draggedAnnotation.layer convertPoint:[recognizer locationInView:self] fromLayer:self.layer];

// inform the layer
//
[_draggedAnnotation.layer setDragState:RMMapLayerDragStateStarting animated:YES];
Expand All @@ -1788,7 +1793,11 @@ - (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer
[CATransaction begin];
[CATransaction setDisableActions:YES];

_draggedAnnotation.position = [recognizer locationInView:self];
CGSize layerSize = _draggedAnnotation.layer.bounds.size;
CGPoint gesturePoint = [recognizer locationInView:self];
CGPoint newPosition = CGPointMake(gesturePoint.x + ((layerSize.width / 2) - _dragOffset.x), gesturePoint.y + ((layerSize.height / 2) - _dragOffset.y));

_draggedAnnotation.position = newPosition;

[CATransaction commit];
}
Expand Down

0 comments on commit 073cd46

Please sign in to comment.