触摸事件 touch view move

- (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;
    }

}

posted @ 2015-11-16 10:56  Kevin_iOS  阅读(320)  评论(0编辑  收藏  举报