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

标签 ios appdelegate uiresponder

已经回答了这样的问题,但是我对答案不满意: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/

相关文章:

ios - 如何使用 UIView 创建自定义翻转动画

ios - 由于版本错误,无法在设备上启动用Swift编写的iOS应用

ios - 复杂 View 中的 SwiftUI 字体缩放

ios - 在 App Delegate 中设置 Init VC?

ios - UITextField 清除故障 - 文本突出显示,选择插入符出现

ios - 调用 resignFirstResponder 在覆盖 firstResponder 中不起作用

iphone - 使用 UITabBarController 时在整个屏幕上覆盖一个 View ?

ios - 保留 Appdelegate

iOS 后台获取和完成 block

ios - 防止父 View Controller 在子 Controller 中接收 UITouch