2013-05-04 62 views
3

由于Event Handling Guide for iOS提到导向的子类,当你创建你自己的UIView子类:事件处理中的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]与否?

回答

2

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

+0

不错的答案。官方指南让我感到困惑。 – hrchen 2013-05-04 18:00:05

+0

好的一个,当我们调用超类事件时的任何想法,而不是它将如何映射下一个响应者。 – subramani 2015-02-12 13:22:44

+0

为例,我添加了子视图uiview添加viewviewcontrol的子视图,如果我在子视图事件处理程序中添加touchesBegan:touches withEvent:event],而不是它如何映射到视图控制器的下一个响应者。 – subramani 2015-02-12 13:28:38