首页 > 移动平台 > 详细

iOS触摸事件

时间:2016-04-09 10:27:43      阅读:183      评论:0      收藏:0      [点我收藏+]

触摸常见的事件有以下几种,触摸事件一般写在view文件中,因为viewController文件有可能控制不止一个view,不适合写触摸事件

 1 // 开始触摸
 2 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
 3     NSLog(@"开始触摸touch");
 4 }
 5 
 6 
 7 // 触摸结束
 8 - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
 9     NSLog(@"触摸结束touch");
10 }
11 
12 
13 // 移动触摸
14 - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
15     NSLog(@"移动触摸touch");
16     
17     // 1.获取触摸手势
18     UITouch *touch = [touches anyObject];
19     
20     // 2.获取触摸的位置(获取一个触摸在某个视图上的位置)
21     CGPoint currentPoint = [touch locationInView:self.superview];
22     
23     // 3.根据触摸的位置改变视图的位置
24     self.center = currentPoint;
25     
26 }
27 
28 
29 // 触摸被打断
30 - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
31     NSLog(@"触摸被打断touch");
32 }

 

iOS触摸事件

原文:http://www.cnblogs.com/zhizunbao/p/5370906.html

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