UIView子类中的事件处理

时间:2013-05-04 09:56:10

标签: iphone ios objective-c uiview uitouch

正如指南Event Handling Guide for 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]这样的超类实现吗?

1 个答案:

答案 0 :(得分:2)

如果你想在你的子视图中吸收触摸,那么你应该'不'调用超级触摸方法。但是,如果要使视图能够将触摸传递给下一个响应者,则可以实现超级触摸方法。希望这说清楚。

相关问题