Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to drag(pan) a view on iPhone screen using UIPanGestureRecognizer

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 656
    Comment on it

    To drag a view we can either use the touch methods of UIViewController or we can use UIPanGestureRecognizer. UIPanGestureRecognizer is much easier and simple to implement. This blog explains how to use it.

    1. Add pan gesture to the view (or any control that is a subclass of UIView) that is to be dragged.
    2. [panImageView addGestureRecognizer:[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinch:)]];
    3. Handle pan
    4. -(void)handlePan:(UIPanGestureRecognizer*)pan {
         CGPoint translation = [pan translationInView:self.view];
          panImageView.center = CGPointMake(panImageView.center.x + translation.x,
                                               panImageView.center.y + translation.y);
          [pan setTranslation:CGPointMake(0, 0) inView:self.view];
      }

    panImageView is the image view which we are going to drag.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: