How do I keep my UIView from "jumping" when dragging it once triggered by UILongPressGestureRecognizer?

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.


- (void)longPress:(UILongPressGestureRecognizer*)receivedGesture
   if (receivedGesture.state == UIGestureRecognizerStateChanged)
       CGPoint translation = [receivedGesture locationInView:self.scrollView]; = 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?



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.

The reason is that your translation point is asking the gesture's location in the view, not the center of the view it's over. If you start to be the button's center, I that should work. Hope this helps!

Need Your Help

Javascript intellisense with Dojo/Dijit is Visual Studio 2008

javascript visual-studio-2008 intellisense dojo

I know that Visual Studio 2008 support JavaScript intellisense as I am using it with Jquery. I am wondering if anyone has ever explored how to get other libraries like Dojo and Dijit to work with ...

What is the right way to check floating-point variables for exact value equality in c#?

c# .net floating-point

I need to check if a floating-point (double) variable a value exactly equals floating-point (double) variable b value. I know floating-point types don't have exact matches to all the decimal values...