ios View拖拽
1 // 当手指在view上移动的时候调用 2 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 3 { 4 5 UITouch *touch = [touches anyObject]; 6 // 0. 获取上一次的位置 7 CGPoint prePoint = [touch previousLocationInView:self]; 8 9 // 1.获取当前的位置 10 CGPoint currentPoint = [touch locationInView:self]; 11 12 CGFloat moveX = currentPoint.x - prePoint.x; 13 CGFloat moveY = currentPoint.y - prePoint.y; 14 15 // 2.改变当前视图的位置,为手指指定的位置 16 CGPoint temp = self.center; 17 temp.x += moveX; 18 temp.y += moveY; 19 self.center = temp; 20 21 }