gpt4 book ai didi

ios - 为什么类 AppDelegate 继承自 UIResponder?

转载 作者:行者123 更新时间:2023-12-01 18:45:35 29 4
gpt4 key购买 nike

已经回答了这样的问题,但是我对答案不满意:Why does AppDelegate inherit from UIResponder? .

我想了解更多细节,因为我正在尝试了解 iOS 应用程序的架构。

据我所知,UIResponder 用于“响应”外力(即触摸事件、运动事件等)的事物。
为什么应用程序的初始化需要是 UIResponder?也许我不明白 AppDelegate 的实例是做什么的。

最佳答案

应用程序委托(delegate)类继承自 UIResponder。

这是为了让委托(delegate)实例可以参与响应者链,从而处理应用程序级别的操作。

编辑:

As of iOS 5 there is a step 6: The app delegate gets the final word on events. Beginning with iOS 5 the app delegate inherits from UIResponder and no longer from NSObject as it did before.

In short: first the view, if the view has a view controller then that, next the superview until the top of the hierarchy, the window. From there to the application and finally to the app delegate.

The addition of the app delegate as potential responder is a welcome addition since we rarely – if ever – subclass UIApplication or UIWindow. But we always have our own app delegate if only to create the window and add the rootViewController in the application:didFinishLaunching… delegate method. So this happens to be the de facto best place for a responder to fall back to if there is none in the entire view hierarchy.



取自:

https://www.cocoanetics.com/2012/09/the-amazing-responder-chain/

关于ios - 为什么类 AppDelegate 继承自 UIResponder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36378126/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com