iphone - 为什么Apple的文档说你不要在UIView的子类中调用父类(super class)的事件处理方法?

标签 iphone

在 Apple 文档《iOS 事件处理指南》中,“Best Practices for Handling Multitouch Events”部分:

If you handle events in a subclass of UIView, UIViewController, or (in rare cases) UIResponder, 
  You should implement all of the event-handling methods (even if it is a null implementation).
  Do not call the superclass implementation of the methods.

If you handle events in a subclass of any other UIKit responder class,
  You do not have to implement all of the event-handling methods.
  But in the methods you do implement, be sure to call the superclass implementation. 
为什么?我不明白这两种情况的第 2 点背后的基本原理。不是要根据不同情况而定吗?

最佳答案

这可能与后面一点有关:

Do not explicitly send events up the responder (via nextResponder); instead, invoke the superclass implementation and let the UIKit handle responder-chain traversal.

如果你处理touchesBegan:withEvent:和touchesEnded:withEvent:,UIView会用touchesMoved:withEvent:做什么?它应该将其转发到响应者链吗?

关于iphone - 为什么Apple的文档说你不要在UIView的子类中调用父类(super class)的事件处理方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3536114/

相关文章:

C++ for iphone崩溃

iphone - UIAlertView的委托(delegate)方法alertViewCancel : does not get called

iphone - 选择的 UIButton 不起作用

iphone - 如何避免滚动时 UITableViewCell 中的图像被刷新?

ios - 如何在通知内容扩展中单击按钮时打开两个特定的 View Controller ?

iphone - 如何将 iPhone 摄像头拍摄的视频显示在屏幕上而不保存?

ios - 如何检查 json 对象是否包含 <null>?

iphone - Objective C - 当用户在 UITextField 中键入文本时更新 UILabel

iphone - IOS 7 - 如何从放置在 UITableViewCell 中的按钮获取 indexPath

iphone - 如何将混响滤波器或任何其他声音效果应用于 .wav 声音文件?