View Controller Programming Guide for iOS---(八)---Using View Controllers in the Responder Chain
Using View Controllers in the Responder Chain
响应链中使用视图控制器
View controllers are descendants of the UIResponder
class and are therefore capable of handling all sorts of events. When a view does not respond to a given event, it passes that event to its superview, traveling up the view hierarchy all the way to the root view. However, if any view in the chain is managed by a view controller, it passes the event to the view controller object before passing it up to the superview. In this way, the view controller can respond to events that are not handled by its views. If the view controller does not handle the event, that event moves on to the view’s superview as usual.
视图控制器继承自UIResponder类,因此它有能力处理所有事件。一般情况下,当一个视图不响应一个事件时,它一直把该事件向上传递给它的父视图,直到根视图。但是,当响应链中的视图是由一个视图控制器管理时,它首先把不响应的事件传递给视图控制器对象,而不是它的父视图。这样视图控制器就可以响应并处理其视图不响应的各种事件。
The Responder Chain Defines How Events Are Propagated to the App
响应链定义了事件如何被传播给应用程序
Figure 7-1 demonstrates the flow of events within a view hierarchy. Suppose you have a custom view that is embedded inside a screen-sized generic view object, which in turn is managed by your view controller. Touch events arriving in your custom view’s frame are delivered to that view for processing. If your view does not handle an event, it is passed along to the parent view. Because the generic view does not handle events, it passes those events along to its view controller first. If the view controller does not handle the event, the event is further passed along to the superview of the generic UIView
object, which in this case is the window object.
图7-1 演示了一个视图层次中的事件流。 假设你又一个自定义视图,它被嵌入一个屏幕大小的普通视图对象中,而该普通视图由视图控制器管理。 传递到你的自定义视图的触摸事件被传递到普通视图进行处理。 如果你的视图不处理一个事件,则该事件被传递给它的父视图。 因为普通视图不处理事件,它把那些事件首先传递给它的视图控制器。 如果视图控制器不处理该事件,然后该事件进一步被传递给普通UIView对象的父视图,在本例中该父视图为window对象。
Figure 7-1 Responder chain for view controllers
Note: The message-passing relationship between a view controller and its view is managed privately by the view controller and cannot be programmatically modified by your app.
注意:一个视图控制器和它的视图之间的消息传递关系是由视图控制器私下管理的,它并不能被应用程序手动更改。
Although you might not want to handle touch events specifically in your view controller, you could use it to handle motion-based events. You might also use it to coordinate the setting and changing of the first responder. For more information about how events are distributed and handled in iOS apps, see Event Handling Guide for iOS.
尽管你可能不想在你的视图控制器中处理触摸事件,但是你可以用它来处理基于运动的事件。你还可能用它来协调(coordinate)设置以及更改第一响应者。关于事件在iOS 应用程序中如何被发布(distrubuted)和处理的更多信息,请看 Event Handling Guide for iOS.
View Controller Programming Guide for iOS---(八)---Using View Controllers in the Responder Chain的更多相关文章
- View Controller Programming Guide for iOS---(七)---Resizing the View Controller’s Views
Resizing the View Controller’s Views A view controller owns its own view and manages the view’s cont ...
- View Controller Programming Guide for iOS---(二)---View Controller Basics
View Controller Basics Apps running on iOS–based devices have a limited amount of screen space for d ...
- View Controller Programming Guide for iOS---(一)---About View Controllers
About View Controllers View controllers are a vital link between an app’s data and its visual appear ...
- View Controller Programming Guide for iOS---(三)---Using View Controllers in Your App
Using View Controllers in Your App Whether you are working with view controllers provided by iOS, or ...
- View Controller Programming Guide for iOS---(四)---Creating Custom Content View Controllers
Creating Custom Content View Controllers 创建自定义内容视图控制器 Custom content view controllers are the heart ...
- View Controller Programming Guid for iOS 笔记
1.View Controller 基础 1.1 View Controller 分类 ViewController分为container view controller 和content view ...
- View Controller Programming Guide for iOS---(六)---Responding to Display-Related Notifications
Responding to Display-Related Notifications 响应跟显示相关的通知 When the visibility of a view controller’s vi ...
- View Controller Programming Guide for iOS---(五)---Resource Management in View Controllers
Resource Management in View Controllers View controllers are an essential part of managing your app’ ...
- 【IOS笔记】View Programming Guide for iOS -1
原文:View Programming Guide for iOS View and Window Architecture Views and windows present your applic ...
随机推荐
- 高性能JS-DOM
用脚本进行DOM操作的代价是很昂贵的,它是富web应用中最常见的性能瓶颈.主要有以下三种问题: 访问和修改DOM元素 修改DOM元素的样式导致repaint和reflow 通过DOM事件处理与用户进行 ...
- scrapy的自动限速(AutoThrottle)扩展
该扩展能根据Scrapy服务器及您爬取的网站的负载自动限制爬取速度. 设计目标 更友好的对待网站,而不使用默认的下载延迟0. 自动调整scrapy来优化下载速度,使得用户不用调节下载延迟及并发请求数来 ...
- 聊聊WiFi Hacks:为何你的Karma攻击不好使了
0.前言 三年前我发表了一篇文章<黑客有办法让你自动连上陌生WiFi>,介绍Karma攻击可以让你的无线设备自动连上黑客的WiFi.当时引起了还算比较热烈的讨论,关于WiFi安全,关于Ka ...
- BUPT 2012复试机考 2T
题目描述 给你一个n*n的矩阵, , 求其矩阵的k次幂,即Pk 输入格式 第一行,一个整数T(0<T<=10),表示要求矩阵的个数. 接下来有T组数据,每组数据格式如下: 第一行:两个数 ...
- PAT 1003 Sharing (25)
题目描写叙述 To store English words, one method is to use linked lists and store a word letter by letter. ...
- HDU 2669 Romantic(扩展欧几里德)
题目链接:pid=2669">http://acm.hdu.edu.cn/showproblem.php?pid=2669 Problem Description The Sky is ...
- 基于TCP应用协议/端口
- 使用string实现一个用于储存那些太大而无法使用 long long 的数
类的定义: class stringInt { public: stringInt(); stringInt(string num); stringInt(int num); stringInt op ...
- 基于ADB框架Robotium跨进程操作
转自:http://blog.csdn.net/qingchunjun/article/details/42580937 2015年2月3日更新: 有些朋友在用真机尝试本方法时,抛出了InputStr ...
- 机器学习经典算法具体解释及Python实现--K近邻(KNN)算法
(一)KNN依旧是一种监督学习算法 KNN(K Nearest Neighbors,K近邻 )算法是机器学习全部算法中理论最简单.最好理解的.KNN是一种基于实例的学习,通过计算新数据与训练数据特征值 ...