gpt4 book ai didi

ios - 为什么 UIViewController 和 UIView 子类 UIResponder?

转载 作者:行者123 更新时间:2023-12-01 16:15:21 26 4
gpt4 key购买 nike

看苹果GLPaint示例代码。

我看到 PaintingViewController 和 PaintingView 都实现了

- (BOOL)canBecomeFirstResponder {
return YES;
}

为什么是二元性?一般来说,不应该只有 UIView 负责处理硬件产生的触摸事件吗?如 The Runtime Interaction Model for Views 中所述

最佳答案

不,有一个简单的例子:

想象一下,你有一个 presentedController .那么你不想要 presentingController处理触摸事件,即使它仍然可见。

View Controller 层次结构在事件传递中非常重要。

UIViewController 中的注释文档:

A view controller is tightly bound to the views it manages and takes part in the responder chain used to handle events. View controllers are also UIResponder objects and are inserted into the responder chain between the view controller’s root view and that view’s superview, which typically belongs to a different view controller. If none of the view controller’s views handle an event, the view controller has the option of handling the event or passing it along to the superview.

关于ios - 为什么 UIViewController 和 UIView 子类 UIResponder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34508516/

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