zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    [ssh] 通过ssh私钥生成公钥的方法
    [redis] hiredis-vip 简单使用
    [redis] redis cli的学习记录
    [ovs] 编写openflow流表的文档指引
    [iptables] 如何用iptables管理桥接模式下的设备
    [qemu][kvm] 在kvm嵌套kvm的虚拟机里启动kvm加速
    [qemu] 差分盘使用
    [yum] yum加速
    [ovs] openvswitch 从源码编译安装
    [qemu] qemu从源码编译安装
  • 原文地址:https://www.cnblogs.com/Ager/p/4883873.html
Copyright © 2011-2022 走看看