首页 > 其他 > 详细

触摸事件 touch view move

时间:2015-11-16 12:19:38      阅读:287      评论:0      收藏:0      [点我收藏+]

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

}

触摸事件 touch view move

原文:http://www.cnblogs.com/applekevin/p/4968324.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!