iphone - UIView 子类中的事件处理

标签 iphone ios objective-c uiview uitouch

作为向导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/

相关文章:

ios - 无法使用 Xcode 构建/运行 iOS 应用程序,但是 'cordova run ios' 工作正常

objective-c - 读取字典元素的预期方法在 'id<NSCopying>' 类型的对象上找不到

ios - 如何从 UITextView 中删除垂直线并在 DALinedTextView 中从左侧键入文本?

ios - 如何将 UDID 添加到 testFlight 门户

iphone - UIImage 旋转自定义度数

iphone - 在隐藏的 Tableview 加载数据时添加背景图像

objective-c - UIPageControl 被取消选择

ios - CoreData 将 NSNumbers 转换为 BOOL

ios - iOS 是否存在导致应用程序崩溃的内存限制?

ios - ScrollView 仅显示最后添加的 subview