Intended function:
After long-pressing a button, have the ability to drag it around on the screen.
Jumping Bug:
When I initially start dragging the button, its center “jumps” to the CGPoint that registered my initial click to trigger the long press. E.g., I long-press click a button on its top right, and once I start dragging the cursor while holding it the button jumps to that “top right” location.
After that jump – all dragging is fine.
Code:
- (void)longPress:(UILongPressGestureRecognizer*)receivedGesture
{
if (receivedGesture.state == UIGestureRecognizerStateChanged)
{
CGPoint translation = [receivedGesture locationInView:self.scrollView];
pannedBadge.center = translation;
}
}
Ultimate question:
What’s the solution here? How do I make it such that the initial dragging moves the button from its original center?
Thanks!
What I usually do for making views draggable is I detect the starting point of the touch, then get the difference with which it (the touch) moved, then set the view’s center as follows: I don’t set it to the place of the touch absolutely, but I set it relatively using the just detected movement of the touch.