gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 21:22:18 26 4
gpt4 key购买 nike

在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com