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

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

 1 //开始时调用
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
NSLog(@"摇一摇开始");
}
//结束时调用
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
NSLog(@"摇一摇结束");
}
//意外情况调用
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{
NSLog(@"意外退出");
}

touches,motion触摸事件响应的更多相关文章

  1. Swift - 触摸事件响应机制(UiView事件传递)

    import UIKit class FatherView: UIView { override func hitTest(point: CGPoint, withEvent event: UIEve ...

  2. iOS_触摸事件与手势识别

    目  录: 一.触摸事件 1.1iOS的输入事件 1.2 触摸事件的处理 1.3 UITouch类中包含五个属性 1.4 UITouch类中包含两个成员函数 1.5响应者链 二.手势识别 2.1使用手 ...

  3. Cocos2d-x中触摸事件

    理解一个触摸事件可以从时间和空间两方面考虑. 1.触摸事件的时间方面 触摸事件的在时间方面,如下图所示,可以有不同的“按下”.“移动”和“抬起”等阶段,表示触摸是否刚刚开始.是否正在移动或处于静止状态 ...

  4. Android: 详解触摸事件如何传递

    当视图的层次结构比较复杂的时候,触摸事件的响应流程也变得复杂. 举例来说,你也许有一天想要制作一个手势极其复杂的 Activity 来折磨你的用户,你经过简单思索,认为其中应该包含一个 PageVie ...

  5. UI和3D场景同时都需要响应触摸事件

    比如战斗场景,UI和3D场景同时都需要响应触摸事件,如果同时响应可能就会出现触摸UI的时候影响到了3D部分.为了解决这个问题在判断3D响应之前要先判断手指是否点击在UI上. 以前NGUI的时候都是自己 ...

  6. [置顶] 使用Android OpenGL ES 2.0绘图之六:响应触摸事件

    传送门 ☞ 系统架构设计 ☞ 转载请注明 ☞ http://blog.csdn.net/leverage_1229 传送门 ☞ GoF23种设计模式 ☞ 转载请注明 ☞ http://blog.csd ...

  7. 【Android Developers Training】 67. 响应触摸事件

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  8. Android OpenGL ES 开发(七): OpenGL ES 响应触摸事件

    像旋转三角形一样,通过预设程序来让对象移动对于吸引注意是很有用的,但是如果你想让你的OpenGL图形有用户交互呢?让你的OpenGL ES应用有触摸交互的关键是,扩展你的GLSurfaceView的实 ...

  9. (转)使用OpenGL显示图像(六)响应触摸事件

    响应触摸事件 编写:jdneo - 原文:http://developer.android.com/training/graphics/opengl/touch.html 让对象根据预设的程序运动(如 ...

随机推荐

  1. [Objective-c 基础 - 2.11] SEL数据类型

    A.概念 1.SEL类型代表方法 2.每个方法都有一个对应的SEL类型的数据 3.实例对象调用方法 (1)编译器会把类的方法包装成SEL类型的数据, (2)根据SEL数据找到方法地址,缓存此地址 (3 ...

  2. [Objective-c 基础 - 2.7] 构造方法、重写init方法

    A.id 万能指针,可以指向任何对象,实质是NSObject的指针,使用的时候不用加上*   B.NSObject中得类方法new 1.完整地创建一个可用对象步骤 (1)分配存储空间 + alloc ...

  3. shell 检测ip的合法性与检测网络掩码的合法性

    有时我们需要检测IP输入的正确性与网络掩码的正确性,用shell脚本写的: #验证ip地址的正确性 check_ip_format() { echo $1 | grep "^[0-9]\{1 ...

  4. [html]HTML <form> 标签的 enctype 属性

  5. linux教程:[4]配置Tomcat开机启动

    http://jingyan.baidu.com/article/6525d4b1382f0aac7d2e9421.html 方法/步骤 1 请自行下载安装配置tomcat的服务器环境 本经验仅仅介绍 ...

  6. iOS 有关自动轮播图片

    //初始化当前视图 _currentImageView = [[UIImageView alloc] init]; [_currentImageView setImageWithURL:[NSURL ...

  7. 模板 lucas

    void extend_gcd(ll a,ll &x,ll b,ll &y){ ){ x=,y=; return; } ll x1,y1; extend_gcd(b,x1,a%b,y1 ...

  8. MySQL Cluster测试过程中的错误汇总--ERROR 1296 (HY000)等等

    参考资料: http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-privilege-distribution.html http://www.cl ...

  9. [Web] What Is JSONP?

    JSONP—or JSON with padding—is a sneaky technique that web developers came up with to work around the ...

  10. careercup-C和C++ 13.8

    13.8 编写一个智能指针类.智能指针是一种数据类型,一般用模板实现,模拟指针行为的同时还提供自动垃圾回收机制.它会自动记录SmartPointer<T*>对象的引用计数,一旦T类型对象的 ...