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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. View Controller Programming Guide for iOS---(四)---Creating Custom Content View Controllers

    Creating Custom Content View Controllers 创建自定义内容视图控制器 Custom content view controllers are the heart ...

  6. View Controller Programming Guid for iOS 笔记

    1.View Controller 基础 1.1 View Controller 分类 ViewController分为container view controller 和content view ...

  7. 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 ...

  8. 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’ ...

  9. 【IOS笔记】View Programming Guide for iOS -1

    原文:View Programming Guide for iOS View and Window Architecture Views and windows present your applic ...

随机推荐

  1. flask可以通过缓存模板或者页面达到性能提升

    flask可通过插件flask-cache缓存页面,或者把模板缓存到memcache里,增加访问速度. 前提是:页面不是频繁变化的.如果你的访问量很大的话,哪怕缓存一两分钟也会大大的提高性能的 Fla ...

  2. Linux索引节点(Inode:no space for device)用满导致的一次故障

    问题描写叙述 在storm測试环境集群上上nimbus和supervisor自己主动挂调.重新启动时显示no space for device,也不能创建,加入文件及文件夹,df -h查看 ilesy ...

  3. iOS开发 检测版本更新

    iOS开发 检测版本更新的实现 苹果给了我们一个接口,能根据应用id请求一些关于应用的信息.我们可以根据返回的信息,来判断版本是否和应用的版本一致,如果不一致,那么就出现新的版本了.这时,就需要向用户 ...

  4. 转:给 Android 开发者的 RxJava 详解

    转自:  http://gank.io/post/560e15be2dca930e00da1083 评注:多图解析,但是我还是未看懂. 前言 我从去年开始使用 RxJava ,到现在一年多了.今年加入 ...

  5. jQuery -> 获取后代元素的三种方法

    假设我们有内容例如以下的html文件,那么怎样选取包括在<p>元素内的<i>元素呢? 邪馬台国の謎と弥生時代 紀元前1000年ごろ.水稲工作の技術をもつ集団が大挙して日本に移住 ...

  6. Solidworks如何显示装饰螺纹线

    1 工具-选项   2 文档属性-上色的装饰螺纹线   3 这样我再插入装饰螺纹线的时候就有效果了

  7. Codeforces Round #258 (Div. 2/A)/Codeforces451A_Game With Sticks

    解题报告 http://blog.csdn.net/juncoder/article/details/38102263 n和m跟木棍相交,问一人取一交点(必须是交点.且取完后去掉交点的两根木棍),最后 ...

  8. UIAutomation使用測试入门

    自己主动化測试的优点: 1.自己主动化能够自己主动測试,不须要人的干预.同一时候还能够不断地反复某一个动作. 2.自己主动化測试在添加了新的功能之后.还能够回归到原理的功能,使其原来的功能不会受到影响 ...

  9. javascript判断一个变量或对象是否存在

    判断一个变量或对象是否存在,是一种常用的操作.我这里收集了几种. //1. 最常用的一种方法.if(typeof v == 'undefined'){ console.log("v is u ...

  10. 基于bootstrap_博客页面

    <!DOCTYPE html> <!-- saved from url=(0036)http://v3.bootcss.com/examples/blog/ --> <h ...