为什么 class AppDelegate 继承自 UIResponder?

Why does class AppDelegate inherit from UIResponder?

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

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

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

应用程序委托class继承自 UIResponder。

这样委托实例就可以参与响应链,从而处理应用程序级操作。

编辑:

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/