ios - 什么时候调用 iOS 的 touches 方法(Cancelled & Ended)?

标签 ios objective-c touches touchesended touchescancelled

我正在尝试使用 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/

相关文章:

ios - Xcode——在 Storyboard中控制+拖动的替代选项,为按钮创建控制转场

iphone - 为什么当触摸次数改变时 touchesBegan 不触发?

ios - 创建自定义 "tickle"UIGestureRecognizer 的最佳方法是什么?

ios - 如何为 UIBarButton 创建自定义图标?

ios - 已处理的构建文件大小超过 100 MB 应用程序文件限制

ios - 在 Swift 中按下 Switch 后条形按钮为零?

iphone - UIView,如何判断触摸何时进入 View

ios - 我们应该使 tapGesture 组件成为 IBAction 还是 IBOutlet 来捕获点击事件?

ios - XCUITest、UIDatePicker、adjustToPickerWheelValue

用于 bool 值的 objective-c getter 装饰器