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:消息。

转载于:https://www.cnblogs.com/bishuai/p/5207523.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值