iPhone 急救人员

发布于 2024-08-28 07:49:40 字数 818 浏览 4 评论 0原文

我对 iPhone 响应链感到困惑。具体来说,在 iPhone 事件处理指南 http:// /developer.apple.com/iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html,我们有以下内容:

第一响应者是应用程序中的响应者对象(通常是UIView 对象)被指定为触摸事件以外的事件的第一个接收者。

但 UIView 是 UIResponder 的子类。 UIResponder 类参考是这样说的:

- (BOOL)canBecomeFirstResponder

返回值

如果接收者可以成为第一响应者,则为 YES,否则为 NO。 讨论

默认情况下返回“否”。如果响应者对象从此方法返回 YES,则它成为第一响应者,并且可以接收触摸事件和操作消息。子类必须重写此方法才能成为第一响应者。

我对明显的矛盾感到困惑。有人可以帮我清理一下吗?

无论如何,我确实设置了一个简单的基于视图的应用程序,并在其视图上调用 canBecomeFirstResponder 和 isFirstResponder 。两人都返回了NO。

I am confused about the iPhone responder chain. Specifically, in the iPhone event handling guide http://developer.apple.com/iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html, we have the following:

The first responder is the responder object in an application (usually a UIView object) that is designated to be the first recipient of events other than touch events.

But UIView is a subclass of UIResponder. And the UIResponder class reference says this:

- (BOOL)canBecomeFirstResponder

Return Value

YES if the receiver can become the first responder, NO otherwise.
Discussion

Returns NO by default. If a responder object returns YES from this method, it becomes the first responder and can receive touch events and action messages. Subclasses must override this method to be able to become first responder.

I am confused by the apparent contradiction. Can anyone clear it up for me?

For what it's worth, I did set up a simple view-based application, and call canBecomeFirstResponder and isFirstResponder on its view. Both returned NO.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤单情人 2024-09-04 07:49:40

术语可能会令人困惑。不要将“第一响应者”视为“初始事件目标”,即作为第一响应者的对象成为所有事件的初始目标。在某些 API 中,这也称为“焦点”,尽管在 Apple API 中通常保留用于描述窗口。

在任何给定时间,应用程序中只有一个第一响应者/初始事件目标。只有单个对象/实例才能成为第一响应者/初始事件目标。类只能定义它们的实例是否有能力成为第一响应者/初始事件目标。如果有意义的话,类只需提供成为应用程序的第一响应者/初始事件目标的能力。例如,文本字段显然需要能够捕获事件,以便它可以使用这些事件来编辑自身。相比之下,静态标签不需要这样的功能。

特定类是否继承自 NSResonder 与该类(或该类的特定实例)是否将其自身设置为第一响应者/初始事件目标无关。该能力仅来自实例对 canBecomeFirstResponder 消息的响应。同一实例可以在一组条件下拒绝成为第一响应者/初始事件目标,然后在条件发生变化时允许它成为第一响应者/初始事件目标。如果愿意的话,类当然可以硬连线状态。

换句话说,第一响应者/初始事件目标是特定实例在特定时间的状态。第一响应者/初始事件目标就像一个烫手山芋或在 UI 中从一个实例传递到另一个实例的令牌。有些班级根本拒绝抢这个烫手山芋。有些人总是这样做,有些人有时会抓住它,而另一些人则忽略它。

The nomenclature can be confusing. Instead of "first responder" think of it as "initial event target" i.e. the object that is the first responder becomes the initial target for all events. In some APIs this is also called the "focus" although in the Apple APIs that is usually reserved to describe windows.

At any given time, there is only one first-responder/intial-event-target in the app. Only individual objects/instances can become a first-responder/intial-event-target. Classes can merely define if their instance have the ability to become a first-responder/intial-event-target. A class need only provide the ability to become the app's first-responder/intial-event-target if it make sense to do so. For example, a textfield obviously needs the ability to trap events so that it can use those event to edit itself. By contrast, a static label needs no such capability.

Whether a particular class inherits from NSResonder has no bearing on whether the class (or a specific instance of the class) will let itself be set as the first-responder/intial-event-target. That ability comes solely from the instances' response to the canBecomeFirstResponder message. The same instance can refuse to be the first-responder/intial-event-target under one set of conditions and then allow it later when conditions change. Classes can of course hardwire the status if they wish.

In other words, first-responder/intial-event-target is a status of a particular instance at a particular time. The first-responder/intial-event-target is like a hot potato or a token that is handed off from instance to instance in the UI. Some classes refuse to grab the hot potato at all. Some always do and others grab it sometimes and ignore it others.

烟若柳尘 2024-09-04 07:49:40

这意味着基本 UIView 无法成为第一响应者 - 它不会对运动事件、编辑菜单消息等执行任何操作。

某些 UIView 子类(如 UITextView)能够成为第一响应者,您可以编写您自己的 UIView 子类也可以这样做。

What this means is that the basic UIView is not able to become first responder - it doesn't do anything with motion events, editing-menu messages, etc.

Some UIView subclasses (like UITextView) are able to become first responder, and you can write your own UIView subclass that does so too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文