首页 > 其他 > 详细

触摸事件

时间:2014-08-27 00:11:46      阅读:424      评论:0      收藏:0      [点我收藏+]

// 一个完整的触摸过程:touchesBegan -> touchesMoved -> touchesEnded

/**

 *  触摸开始(手指刚碰到view)

 */

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

/**

 *  触摸ing(手指在view上面挪来挪去)

 */

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [touches anyObject];

    // 当前触摸点

    CGPoint current = [touch locationInView:self];

    // 上一个触摸点

    CGPoint previous = [touch previousLocationInView:self];

    // 修改当前view的位置(中点)

    CGPoint center = self.center;

    center.x += current.x - previous.x;

    center.y += current.y - previous.y;

    self.center = center;

}

/**

 *  触摸结束(手指离开view)

 */

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

/**

 *  触摸手势取消(比如说来电时,手势也就中断了)

 */

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event

触摸事件

原文:http://www.cnblogs.com/bluceZ/p/3938415.html

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