[iOS UI进阶 - 3.1] 触摸事件的传递
UIApplication会从事件队列中取出最前面的事件,并将事件分发下去以便处理,通常,先发送事件给应用程序的主窗口(keyWindow)
主窗口会在视图层次结构中找到一个最合适的视图来处理触摸事件,这也是整个事件处理过程的第一步
找到合适的视图控件后,就会调用视图控件的touches方法来作具体的事件处理
touchesBegan…
touchesMoved…

userInteractionEnabled = NO
隐藏
hidden = YES
透明
alpha = 0.0 ~ 0.01
提示:UIImageView的userInteractionEnabled默认就是NO,因此UIImageView以及它的子控件默认是不能接收触摸事件的
找到最合适的视图控件后,就会调用控件的touches方法来作具体的事件处理
touchesBegan…
touchesMoved…
touchedEnded…
这些touches方法的默认做法是将事件顺着响应者链条向上传递,将事件交给上一个响应者进行处理

For the app on the left, the event follows this path:
The initial view attempts to handle the event or message. If it can’t handle the event, it passes the event to itssuperview, because the initial view is not the top most view in its view controller’s view hierarchy.
The superview attempts to handle the event. If the superview can’t handle the event, it passes the event to its superview, because it is still not the top most view in the view hierarchy.
The topmost view in the view controller’s view hierarchy attempts to handle the event. If the topmost view can’t handle the event, it passes the event to its view controller.
The view controller attempts to handle the event, and if it can’t, passes the event to the window.
If the window object can’t handle the event, it passes the event to the singleton app object.
If the app object can’t handle the event, it discards the event.
The app on the right follows a slightly different path, but all event delivery paths follow these heuristics:
A view passes an event up its view controller’s view hierarchy until it reaches the topmost view.
The topmost view passes the event to its view controller.
The view controller passes the event to its topmost view’s superview.
Steps 1-3 repeat until the event reaches the root view controller.
The root view controller passes the event to the window object.
The window passes the event to the app object.
自定义一个view
实现view的touches方法,在方法内部实现具体处理代码
通过touches方法监听view触摸事件,有很明显的几个缺点
必须得自定义view
由于是在view内部的touches方法中监听触摸事件,因此默认情况下,无法让其他外界对象监听view的触摸事件
不容易区分用户的具体手势行为
iOS 3.2之后,苹果推出了手势识别功能(Gesture Recognizer),在触摸事件处理方面,大大简化了开发者的开发难度


[iOS UI进阶 - 3.1] 触摸事件的传递的更多相关文章
- [iOS UI进阶 - 3.0] 触摸事件的基本处理
A.需要掌握和练习的 1.介绍事件类型2.通过按钮的事件处理引出view的事件处理3.响应者对象 --> UIResponder --> UIView4.view的拖拽* 实现触摸方法,打 ...
- IOS view拖拽(触摸事件)
• iOS中的事件可以分为3大类型 触摸事件 加速计事件 远程控制事件 响应者对象 • 在iOS中不是任何对象都能处理事件,只有继承了UIResponder的对象才能接收并处理事 件.我们称之为“响应 ...
- [iOS UI进阶 - 6.0] CALayer
A.基本知识 1.需要掌握的 CALayer的基本属性 CALayer和UIView的关系 position和anchorPoint的作用 2.概念 在iOS中,你能看得见摸得着的东西基本上都是U ...
- iOS UI进阶-2.0 CALayer
在iOS中,你能看得见摸得着的东西基本上都是UIView,比如一个按钮.一个文本标签.一个文本输入框.一个图标等等,这些都是UIView 其实UIView之所以能显示在屏幕上,完全是因为它内部的一个图 ...
- iOS边练边学--触摸事件以及能够拖拽的UIView的练习
一.用户在使用APP的过程中,会产生各种各样的事件.iOS中的事件可以分为3大类型: 二.响应者对象 在iOS中只有继承了了UIResponder的对象才能接受并处理事件,这样的对象称之为“响应者对象 ...
- iOS UITableView UIScrollView 的支持触摸事件
在使用了 UITableView 或UIScrollView的controller 里无法响应触摸事件touch事件, 自定义tableView.scrollView #import <UIKi ...
- [iOS UI进阶 - 5.0] 手势解锁Demo
A.需求 1.九宫格手势解锁 2.使用了绘图和手势事件 code source: https://github.com/hellovoidworld/GestureUnlockDemo B ...
- [iOS UI进阶 - 4.0] 涂鸦app Demo
A.需求 1.超简易画图,只有一种画笔 2.清屏功能 3.回退功能 4.保存功能 5.使用了cocos2D code source: https://github.com/hellovoidwor ...
- Android: 详解触摸事件如何传递
当视图的层次结构比较复杂的时候,触摸事件的响应流程也变得复杂. 举例来说,你也许有一天想要制作一个手势极其复杂的 Activity 来折磨你的用户,你经过简单思索,认为其中应该包含一个 PageVie ...
随机推荐
- awk 传入外部参数
awk 传入外部参数 num1=1.1 num2=2.2 result=$(awk -v n1=$num1 -v n2=$num2 'BEGIN{print (n2>n1)?1:0}')
- [POJ1236]Network of Schools(并查集+floyd,伪强连通分量)
题目链接:http://poj.org/problem?id=1236 这题本来是个强连通分量板子题的,然而弱很久不写tarjan所以生疏了一下,又看这数据范围觉得缩点这个事情可以用点到点之间的距离来 ...
- jquery select操作和联动操作
(function(){ //select操作 $.fn.loadSelect = function(opt){ opt = $.extend({}, { required:false,//为真则添加 ...
- word编辑器解码集合
$(document).ready(function () { $(".content").each(function () { var content = $(this).htm ...
- UVa 11995 I Can Guess the Data Structure!
做道水题凑凑题量,=_=||. 直接用STL里的queue.stack 和 priority_queue模拟就好了,看看取出的元素是否和输入中的相等,注意在此之前要判断一下是否非空. #include ...
- OK335xS dhcpcd porting
/********************************************************************** * OK335xS dhcpcd porting * 说 ...
- 学习PHP C扩展之面向对象开发方式 (转)
PHP OOP面向对象之C语言开发方式 学习PHP C扩展有一段时间了,PHP手册里大部分讲的PHP的函数开发方式,网上找OOP资料比较少,想起上个月测试redis 的时候,下载PHP扩展redis源 ...
- CCapture directshow 视频捕获类
// Capture.h for class CCapture #include <dshow.h> #include <qedit.h> #include <atlba ...
- HDU 5762 Teacher Bo
Teacher Bo Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tota ...
- 11、WebView 使用总结
<WebView android:id="@+id/webview" android:background="@color/white" android: ...