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.
- Add pan gesture to the view (or any control that is a subclass of UIView) that is to be dragged.
[panImageView addGestureRecognizer:[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinch:)]];
- Handle pan
-(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)