IT English Collection (25) of Responder object

来源:互联网 发布:淘宝仓库修改躲避排查 编辑:程序博客网 时间:2024/05/25 16:28

1 前言

    本文主要介绍了响应对象的相关内容,和事件在响应链上的传递过程。

    转载请注明出处:http://blog.csdn.net/developer_zhang

2 详述

2.1 原文

  A responder is an object that can respond to events and handle them. All responder objects are instances of classes thatultimately inherit from UIResponder (iOS) or NSResponder (OS X). These classes declare aprogrammatic interface for event handling and define a default behavior for responders. The visible objects of an app are almost always responders—for example, windows, views, and controls—and the app object is a responder as well. In iOS, view controllers (UIViewController objects) are also responder objects.




  To receive events, a responder must implement the appropriate event-handling methods and,in some cases, tell the app that it can become the first responder.

The First Responder Receives Some Events First

  In an app, the responder object that first receives many kinds of events is known as the first responder. It receives key events,motion events, and action messages, among others. (Mouse events and multitouch events first go to the view that is under the mouse pointer or finger; that view might or might not be the first responder.) The first responder is typically the view in a window that an app deems bestsuited for handling an event. To receive an event, the responder must alsoindicate its willingness to become first responder; it does this in different ways for eachplatform:

// OS X- (BOOL)acceptsFirstResponder { return YES; } //iOS- (BOOL)canBecomeFirstResponder { return YES; }

  In addition to receiving event messages, a responder can receive action messages that have no target specified. (Action messages are sent by controls such as buttons and controls when usersmanipulate them.)

The Responder Chain Enables Cooperative Event Handling
 

  If the first responder cannot handle an event or action message, itforwards it to the “next responder” in a linkedseries called the responder chain. The responder chain allows responder objects to transferresponsibility for handling an event or action message to other objects in the app. If an object in the responder chain cannot handle the event or action, it passes the message to the next responder in the chain. The message travels up the chain, toward higher-level objects, until it is handled. If it isn't handled, the appdiscards it.


Figure 17-1  The responder chain for iOS (left) and OS X (right)


The path of an event. The general path of an event up the responder chain starts with a view—the first responder or the view under the mouse pointer or finger. From there, itproceeds up the view hierarchy to the window object and then to the global app object. However, the responder chain for events in iOS adds avariation to this path: If a view is managed by a view controller and if the view cannot handle an event, the view controller becomes the next responder.

  The path of an action message. For action messages, both OS X and iOS extend the responder chain to other objects. In OS X, the responder chain for action messages differs for an app based on the documentarchitecture, an app that uses window controllers (NSWindowController), and an app that fits neither of thosecategories. Additionally, if an app on OS X has both a key window and a main window, the responder chain along which an action message travels mightinvolve the view hierarchies of both windows.

2.2 生词

ultimately['ʌltɪmətlɪ]adv. 最后;根本;基本上

inherit[ɪn'herɪt]vt. 继承;遗传而得

programmatic [prəʊɡrə'mætɪk]adj. 节目的;标题音乐的,纲领性

appropriate[ə'prəʊprɪət]adj. 适当的

in some cases在某些情况下;有时候

motion['məʊʃ(ə)n]n. 动作;移动;

deems[diːm]vt. 认为,视作;相信

suited['suːtɪd]adj. 合适的

indicate['ɪndɪkeɪt]vt. 表明;指出;预示;象征

willingness['wɪlɪŋnɪs]n. 乐意;心甘情愿;自动自发

platform['plætfɔːm]n. 平台;月台,站台;坛;讲台

in addition to之外

manipulate[mə'nɪpjʊleɪt]vt. 操纵;操作

Cooperative[kəʊ'ɒpərətɪv]adj. 合作的;合作社的

forwards['fɔːwədz]adv. 向前;今后

series['sɪəriːz; -rɪz]n. 系列,连续;[电] 串联;级数;丛书

responsibility[rɪ,spɒnsɪ'bɪlɪtɪ]n. 责任,职责;义务

discardsv.丢弃

general['dʒen(ə)r(ə)l]adj. 一般的,普通的;综合的;大体的

proceed[prə'siːd]vi. 开始;继续进行;发生;行进

variation[veərɪ'eɪʃ(ə)n]n. 变化;[生物] 变异,变种

extend[ɪk'stend; ek-]vt. 延伸;扩大;推广;

architecture['ɑːkɪtektʃə]n. 建筑学;建筑风格;建筑式样

categories['kætɪg(ə)rɪz]n. 类别(category的复数);分类

additionally [ə'dɪʃənəlɪ]adv. 此外;又,加之

involve[ɪn'vɒlv]vt. 包含;牵涉;使陷于;潜心于

3 结语

  以上是所有内容,希望对大家有所帮助。

原创粉丝点击