iOS事件(触摸,移动,晃动)

 1 //开始触摸
 2 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 3 {
 4     NSLog(@"你触摸了屏幕");
 5 }
 6 //移动
 7 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
 8 {
 9     NSLog(@"手指移动");
10 }
11 //触摸结束
12 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
13 {
14     NSLog(@"触摸结束");
15 }
16 //中断触摸
17 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
18 {
19     NSLog(@"中断触摸");
20 }
21 //开始摇晃手机
22 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
23 {
24     NSLog(@"开始摇晃");
25 }
26 //摇晃被中断
27 - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
28 {
29     NSLog(@"中断摇晃");
30 }
31 //摇晃结束
32 - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
33 {
34     NSLog(@"摇晃结束");
35 }

新建一个Controller,可以通过添加以上的基本的方法来响应基本的一些事件。

在给定的触摸阶段中,如果发生新的触摸动作或已有的触摸动作发生变化,应用程序就会发送这些消息:

当一个或多个手指触碰屏幕时,发送touchesBegan:withEvent:消息。

当一个或多个手指在屏幕上移动时,发送touchesMoved:withEvent:消息。

当一个或多个手指离开屏幕时,发送touchesEnded:withEvent:消息。

当触摸序列被诸如电话呼入这样的系统事件所取消时,发送touchesCancelled:withEvent:消息。

posted @ 2016-02-22 16:27  骗人的孩纸  阅读(852)  评论(0编辑  收藏  举报