gpt4 book ai didi

iphone - UIView 子类中的事件处理

转载 作者:搜寻专家 更新时间:2023-10-30 20:19:29 24 4
gpt4 key购买 nike

作为向导Event Handling Guide for iOS提到,当您创建自己的 UIView 子类时:

所有处理触摸的 View 都希望接收到完整的触摸事件流,因此当您创建子类时,请记住以下规则:

 - If your custom responder is a subclass of UIView or UIViewController, you should implement all of the event handling methods.

- If you subclass any other responder class, you can have a null implementation for some of the event methods.

**- In all methods, be sure to call the superclass implementation of the method.**

但是在指南的“处理多点触控事件的最佳实践”部分,它还说:

如果您在 UIView、UIViewController 或 UIResponder 的子类中处理事件:

 - Implement all of the event handling methods, even if your implementations of those methods do nothing.

**- Do not call the superclass implementation of the methods.**

如果您在任何其他 UIKit 响应器类的子类中处理事件:

 - You do not have to implement all of the event handling methods.

**- In the methods you do implement, be sure to call the superclass implementation. For example, [super touchesBegan:touches withEvent:event].**

这是我的问题,我是否应该像 [super touchesBegan:touches withEvent:event] 那样调用父类(super class)实现?

最佳答案

如果你想在子类 View 中吸收触摸,那么你不应该调用 super touches 方法。但是,如果你想让 View 能够将触摸传递给下一个响应者,那么你可以实现 super touches 方法。希望这能说明问题。

关于iphone - UIView 子类中的事件处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16372982/

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