iPhone第一响应者 [英] iPhone first responders

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

问题描述

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

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:

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

但是UIView是UIResponder的子类.而且UIResponder类参考说:

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

- (BOOL)canBecomeFirstResponder

返回值

如果接收者可以成为第一响应者,则为是",否则为否". 讨论

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

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

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?

对于它的价值,我确实建立了一个简单的基于视图的应用程序,并在其视图上调用canBecomeFirstResponder和isFirstResponder.都返回NO.

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.

推荐答案

这意味着基本的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.

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

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

这篇关于iPhone第一响应者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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