3

正如iOS 事件处理指南中提到的,当您创建自己的 UIView 子类时:

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

 - 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]吗?

4

1 回答 1

2

如果您想在子类视图中吸收触摸,那么您应该“不”调用 super touches 方法。但是,如果您想让视图能够将触摸传递给下一个响应者,那么您可以实现超级触摸方法。希望这可以说清楚。

于 2013-05-04T11:14:59.587 回答