一、注册拖动动画
UIPanGestureRecognizer * panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self
action:@selector(move:)];
[self.imageView addGestureRecognizer:panGestureRecognizer];
注:vLight就是要加入拖动的View子类。
二、拖动处理函数
- (void) move:(id )sender{
UIPanGestureRecognizer *PANGETURE = sender;
PANGETURE.view.center = CGPointMake(PANGETURE.view.center.x + movePoints.x, PANGETURE.view.center.y + movePoints.y);
[PANGETURE setTranslation:CGPointMake(0, 0) inView:self.view];
}
注:最后一句为关键代码,因为拖动起来一直是在递增,所以每次都要用setTranslation:方法将每次触摸都设置为0位置,这样才不至于不受控制般滑动出视图。