- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
//找到一个触摸
UITouch *touch = [touches anyObject];
//touch.view 是指touch发生在哪一个view上
if (touch.view == _moveView) {
//previousLocationInView 得到上一个点在self.view中的坐标
CGPoint previousPoint = [touch previousLocationInView:self.view];
//找到触摸在view上的位置
CGPoint point = [touch locationInView:self.view];
CGFloat xOffset = point.x - previousPoint.x;
CGFloat yOffset = point.y - previousPoint.y;
CGPoint newCenteter = CGPointMake(_moveView.center.x+xOffset, _moveView.center.y + yOffset);
_moveView.center = newCenteter;
}
}
转载于:https://www.cnblogs.com/applekevin/p/4968324.html