touches,motion触摸事件响应

//触摸事件响应需要重写方法

1
// 触摸时触发该方法(消息发送) 2 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ 3 UITouch *touch = [touches anyObject]; 4 CGPoint point = [touch locationInView:self.rootView.touchView];//locationInView:得到当前点击下在指定视图中位置的坐标 5 NSLog(@"触摸开始:%.2f,%.2f",point.x,point.y); 6 } 7 //但触摸移动时触发该事件 8 - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ 9 10 UITouch *touch = [touches anyObject]; 11 CGPoint point1 = [touch locationInView:self.rootView.touchView]; 12 CGPoint point2 = [touch previousLocationInView:self.rootView.touchView];//previouslocationInView:得到当前点的前一个点在指定视图中位置的坐标 13 } 14 // 触摸结束时触发该方法(消息发送) 15 - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ 16 NSLog(@"触摸结束"); 17 } 18 //发生其他情况,如来电话或意外退出时,执行该方法 19 - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ 20 21 }
//手机摇一摇实现要重写方法

1
//开始时调用 2 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{ 3 NSLog(@"摇一摇开始"); 4 } 5 //结束时调用 6 - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{ 7 NSLog(@"摇一摇结束"); 8 } 9 //意外情况调用 10 - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{ 11 NSLog(@"意外退出"); 12 }

 

转载于:https://www.cnblogs.com/Ager/p/4883873.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值