而如果要想更精细的处理,我们还需要借助touchesBegan,touchesMoved,touchesEnded等触摸方法。这些方法都是UIResponder中的方法。视图控制器和视图类,都是UIResponder的子类。正是这个类,让UIView等相关触摸事件得以响应。
具体方法介绍如下:
1,func touchesBegan(touches: NSSet,withEvent event: UIEvent)
touches是UITouch的集合,通过UITouch我们可以检测触摸事件的属性,是单拍还是双拍,还有触摸的位置等。
2,func touchesMoved(touches: NSSet,51); font-family:arial; font-size:14px">
告诉接收者一个或者多个手指在视图或者窗口上触发移动事件。
默认不允许多点触摸。如果要接收多点触摸事件必须将UIView的属性设置为true。
3,func touchesEnded(touches: NSSet,51); font-family:arial; font-size:14px">
当一个触摸事件结束时发出的UITouch实例对象。
4,func touchesCancelled(touches: NSSet,51); font-family:arial; font-size:14px">
通知接收者当系统发出取消事件的时候(如低内存消耗的告警框)
下面通过一个样例演示触摸事件得用法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
@H_502_172@