码迷,mamicode.com
首页 > 移动开发 > 详细

iOS触摸事件

时间:2016-04-09 10:29:38      阅读:208      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!