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.

时间: 2024-08-09 05:40:03

View Controller Programming Guide for iOS---(八)---Using View Controllers in the Responder Chain的相关文章

M2在奋斗之ios开发--View Controller pragramming guide for IOS中文版

About View Controllers 视图控制器是应用程序数据和其视觉外形之间的一个至关重要的链接.无论何时,应用程序显示一个用户界面,其显示的内容都是由一个或一组互相合作的视图控制器管理.因此,视图控制器给你建立的应用程序提供了骨架. iOS提供了很多内置的视图控制器类来支持标准用户界面块(piece),比如导航和标签栏.作为开发应用程序的一部分,你还可以实现一个或多个自定义控制器来显示应用程序的特定内容. 概述 在模型-视图-控制器(MVC)设计模式里,视图控制器是传统的控制器对象,

笔记:View Programming Guide for iOS -1

原文:View Programming Guide for iOS View and Window Architecture Views and windows present your application’s user interface and handle the interactions with that interface. UIKit and other system frameworks provide a number of views that you can use a

View Programming Guide for iOS 视图编程指南 - iOS

1 有关 Windows and Views 每个应用都至少有一个 window 和一个 view. 1.1 添加额外的 Window 一般在有外界显示设备的时候才需要添加额外的 window 下面的代码举了一个例子,这里假定对象实现了方法 externalWindow,externalWindow 存储一个 window 的引用 - (void)configureExternalDisplayAndShowWithContent:(UIViewController*)rootVC { // C

《view programming guide for iOS 》之可以使用动画效果的属性

frame—Use this to animate position and size changes for the view.  ,框架,可以视图动态改变大小和位置 bounds—Use this to animate changes to the size of the view.      ,可以改变视图的大小 center—Use this to animate the position of the view.           ,可以改变视图的位置 transform—Use t

App Programming Guide for iOS

About iOS App Architecture

【IOS笔记】View Controller Basics

View Controller Basics   视图控制器基础 Apps running on iOS–based devices have a limited amount of screen space for displaying content and therefore must be creative in how they present information to the user. Apps that have lots of information to display

核心动画编程指南Core Animation Programming Guide - iOS

1 有关核心动画 1.1 概览 1.1.1 Core Animation 管理应用的内容 核心是 layer objects, 1.1.2 更改 layer 触发动画 Like views, layer objects have a bounds rectangle, a position onscreen, an opacity, a transform, and many other visually-oriented properties that can be modified. 更改这

iOS开发 - View Controller 的paging

在学习开源中国ios 源码时,发现其实现view controllers 的paging的方法如下: 第一.定义一个容器类的view controller,类似于UIPageViewController. 该vc的主要由两部分组成: a 一个title view,用来表明当前内容是什么,并且能够相应用户的点击,切换content b 一个table view controller (通过addChildViewController添加,并将table view controller 的view

iOS 8 & Xcode 6:解决Failed to instantiate the default view controller for UIMainStoryboardFile 'Main'

把默认Main.storyboard的默认scene(情景)删除后,拖入新的ViewController,并指定其关联的ViewController类,运行程序.控制台输出信息如下: Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set? 原因是没设置初始化ViewController.在场景