iphone - 响应链在 iPhone 中是如何工作的? "next responders"是什么?

标签 iphone objective-c ios uiresponder

文档是这么说的:

If the first responder [to an event or action message] cannot handle an event or action message, it forwards it to the “next responder” in a linked series called the responder chain. The responder chain allows responder objects to transfer responsibility for handling an event or action message to other objects in the application.

If an object in the responder chain cannot handle the event or action, it resends 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 application discards it.

好的,下一个响应者是什么?

是父 View 吗?背后的观点? iOS 如何决定什么是第一响应者和第二响应者?

最佳答案

第一响应者是 Cocoa 中一个非常具体的概念。 iOS 唯一决定设置 First Responder 的时间是文本字段获得焦点时。在所有其他时间,您必须明确控制您希望哪个对象成为第一响应者(请参阅 -canBecomeFirstResponder、-becomeFirstResponder)。

没有第二响应者这样的东西。

所有的响应者都有一个NextResponder,(可以是nil)。这意味着从任何响应者开始,可能有(但可能不是)任意长度的响应者链(responder -> nextResponder -> nextResponder -> etc),事件沿着这些链传递,直到它们被处理.

默认链可以是 view -> superview -> superview 但也可能包括 UIViewControllers, UIWindows, UIWindowControllers, UIApplication 等等,所以它在很大程度上取决于你的对象层次结构(不仅仅是您的 View 层次结构 - 所以不,您不能说 nextResponder 始终是父 View )。在 OSX 10.6 上,默认链对于不同类型的事件和操作甚至是不同的,甚至可以包括您的应用委托(delegate),它可能是也可能不是响应者,我不确定在 iOS 中是否属于这种情况。

默认链只是默认链,因此在您管理了 First Responder 之后,您可以将项目插入、删除和附加到它的响应链以实现您想要的目标。

响应链非常重要和复杂,您应该花时间阅读有关它的 Apple 文档。

关于iphone - 响应链在 iPhone 中是如何工作的? "next responders"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6741746/

相关文章:

objective-c - 带有纬度和经度的 swift 中的 CLLocation 对象

ios - 更新到 ios8.3 后丢失 safari 远程调试

ios - 显示通知的键盘不叫 iOS 12

iphone - 这些位掩码实际上是如何工作的?

c# - 我们怎样才能降低iOS游戏的耗电量呢?

iphone - 按手机联系人顺序在 UItableview 中显示联系人

iphone - Cocos2d 数组中的随机对象未被调用

ios - 将 View 从另一个选项卡的模态推送到导航

objective-c - WebView : decidePolicyForNavigationAction: request: frame: decisionListener: called multiple times

java - 用户是否可以授予应用程序权限,以便该应用程序可以在需要时让设备被发现?