iOS中第一响应者的正式定义是什么? [英] What is a formal definition of a first responder in iOS?

查看:354
本文介绍了iOS中第一响应者的正式定义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,第一个响应者对象是根据输入活动等接收回调信号,并且它会将其冒充链,直到可以找到愿意处理它的响应者。

I understand that a first responder object is the receives a callback signal according to input activity, etc and that it will bubble it up the chain until a responder willing to handle it can be found.

但更正式的是,第一响应者的范围是什么?例如,它是应用程序范围内的响应者吗?似乎第一响应者只是说这个特定对象将收到交互通知。另一个响应者可以窃取第一响应者状态吗?

But more formally, what is the scope of the first responder? For instance, is it an application-wide responder? It seems like being a first responder is simply saying that this particular object will receive notification of interaction. Can another responder steal the first responder status?

请向我解释或指导一些相关信息。我已经阅读了Apple对响应者的一般解释。我正在寻找一个更加内置的解释。

Please explain or direct me to some pertinent information. I've read Apple's general explanation of what a responder is. I'm looking for an explanation that's little more built out.

推荐答案

iOS中第一个响应者的范围由视图决定层次结构。请记住,响应者是响应者层次结构的一部分,并由Apple的文档定义:

The scope of a first responder in iOS is determined by view hierarchy. Remember, a responder is part of a hierarchy of responders, and defined by Apple's documentation:


响应者是一个可以响应事件的对象并处理它们。所有响应者对象都是最终继承自UIResponder(iOS)或NSResponder(OS X)的类的实例。

A responder is an object that can respond to events and handle them. All responder objects are instances of classes that ultimately inherit from UIResponder (iOS) or NSResponder (OS X).

实际上,所有响应者都是是一系列潜在响应者的一部分,一直到应用程序本身。这意味着响应者的范围取决于您必须走多远才能获得能够处理响应的对象。如果第一个响应者是UI元素,例如UITextField,则您的范围与该响应者的范围相关联。

Practically speaking, all responders are part of a chain of potential responders leading all the way up to the Application itself. This means that the scope of the responder is determined by how far up the chain you have to go to get an object capable of handling a response. If the first responder is a UI element, such as a UITextField, your scope is tied to the scope of that responder.

在此图像中,显示iOS第一响应者层次结构在左侧(右侧的OS X):

In this image, iOS first responder hierarchy is shown on the left (OS X on the right):

要回答问题的第二部分,是的,对象可以先窃取响应者状态,如果用户与元素交互,例如:

To answer the second part of question, yes, objects can 'steal' first responder status if a user interacts with an element, for instance:


  1. 用户点击textField1。它现在是第一个响应者。

  2. 用户点击textField2。它接管了textField1的第一响应者状态。

...并且你可以通过某些功能赋予他们第一响应者状态: / p>

...and you can bestow first responder status on them with certain functions:

[textField3 becomeFirstResponder]; //This is now the first responder
[textField4 becomeFirstResponder]; //Now textField4 has 'stolen' first responder status
[textField4 resignFirstResponder]; //The text field has resigned its first responder status to the next level up

对于其他阅读此内容的人谁没有在这方面找到Apple的文档,一个很好的起点是这里的Responder层次结构解释:
https://developer.apple.com/library/ios/documentation/General/Conceptual/Devpedia-CocoaApp/Responder.html

For anyone else reading this who hasn't hit up Apple's documentation on this, a good starting place is the Responder hierarchy explanation found here: https://developer.apple.com/library/ios/documentation/General/Conceptual/Devpedia-CocoaApp/Responder.html

我希望这有帮助!

这篇关于iOS中第一响应者的正式定义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆