UIPanGestureRecognizer * panGesture = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGesture:)];
[redView addGestureRecognizer:panGesture];
[panGesture release];
- (void)panGesture:(UIPanGestureRecognizer *)panGesture
{
CGPoint point = [panGesture translationInView:panGesture.view];
panGesture.view.transform = CGAffineTransformMakeTranslation(point.x, point.y);
panGesture.view.transform = CGAffineTransformTranslate(panGesture.view.transform, point.x, point.y);
将之前增量清零
[panGesture setTranslation:point inView:panGesture.view];
获取的是手指位置的改变量 , 存储在x轴以及y轴的改变量
CGPoint point = [panGesture translationInView:panGesture.view];
panGesture.view.center = CGPointMake(panGesture.view.center.x+ point.x,panGesture.view.center.y+ point.y);
将之前的增量清零 重置之前的增量
[panGesture setTranslation:CGPointZero inView:panGesture.view];
panGesture.view.backgroundColor = [UIColor random];
}