Shashank Kulshrestha
Shashank Kulshrestha

Reputation: 1556

Trying to move UIImageView on UIPanGestureRecognizer

Hi Guys I am trying to move UIImageView using the following code on UIPanGestureRecognizer

 CGPoint pointMove;
 pointMove.x = holderView.center.x + (currentPoint.x - lastPoint.x);
 pointMove.y = holderView.center.y + (currentPoint.y - lastPoint.y);

 holderView.center = pointMove;

 lastPoint = currentPoint;

But this is giving a jumble on moving not moving smoothly. Please help me

Upvotes: 0

Views: 3857

Answers (2)

Satish Azad
Satish Azad

Reputation: 2312

Try to change this in your code.

  CGPoint translation = [gestureRecognizer translationInView:[holderView superview]];

    [holderView setCenter:CGPointMake([piece center].x + translation.x, [piece center].y + translation.y)];

I hope this will solve your problem

Upvotes: 1

Nitin Gohel
Nitin Gohel

Reputation: 49730

i got a best example of Dragging Image using UIPanGestureRecognizer

please download this demo and check it :-

https://github.com/elc/iCodeBlogDemoPhotoBoard

hope it's help's you

here are some same Asked Question please visit link:-

Drag + Rotation using UIPanGestureRecognizer touch getting off track

swapping images using pan gesture

How to use UIPanGestureRecognizer to move object? iPhone/iPad

Upvotes: 2

Related Questions