我正在尝试使用 UIBezierPath 编写程序并触摸方法。
我对两种触摸方法感到困惑:
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
我不明白何时调用这些方法或如何调用它们。起初我以为它们都是一样的,直到我在某个地方读到它们不是。问题是:我如何调用其中一种方法,它们之间有何不同?
最佳答案
你不应该调用这些方法。它们由 Cocoa 框架为您调用。你只需要实现它们来为你的 UIResponser
的子类提供正确的(原生的)行为。或您的自定义UIGestureRecognizer
子类。
请引用Apple's guide关于子类 UIResponder
有关如何实现这些方法的更多详细信息。
来自 Apple's documentation关于 - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
方法:
Tells the responder when one or more fingers are raised from a view or window.
来自 Apple's documentation关于
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
方法:Sent to the receiver when a system event (such as a low-memory warning) cancels a touch event.
关于ios - 什么时候调用 iOS 的 touches 方法(Cancelled & Ended)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34962463/