ios - 什么是 UIControlEventTouchCancel?

标签 ios uibutton uicontrolevents

当用户在我的应用程序中点击并按住 UIButton 时,会触发 UIControlEventTouchCancel 事件。 UIControl 的 Apple 文档没有关于此事件的任何详细说明。为什么会触发?这有什么用途?

[button addTarget:key action:@selector(keyUp:) forControlEvents:UIControlEventTouchUpInside];
[button addTarget:key action:@selector(keyUp:) forControlEvents:UIControlEventTouchUpOutside];
[button addTarget:key action:@selector(keyCancel:) forControlEvents:UIControlEventTouchCancel];
[button addTarget:key action:@selector(keyDown:) forControlEvents:UIControlEventTouchDown];

最佳答案

According to the documentation , 一个 UIControlEventTouchCancel事件是由于:

A system event canceling the current touches for the control.



因此,触摸结束并不是由于用户输入,而是由于系统事件(例如内存不足警告或应用程序进入后台)。 我不知道为什么您只需按住按钮即可触发它。

我很确定这与 UIResponder 的事件类似(如果不是由事件引起的)。的 touchesCancelled:withEvent: 事件。这方面的文档稍微详细一些:

This method is invoked when the Cocoa Touch framework receives a system interruption requiring cancellation of the touch event; for this, it generates a UITouch object with a phase of UITouchPhaseCancel. The interruption is something that might cause the application to be no longer active or the view to be removed from the window

关于ios - 什么是 UIControlEventTouchCancel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34931183/

相关文章:

iphone - UIButton 复选框

ios - 如何从自定义控件发送 "UIControlEventValueChanged"事件?

ios - swift 3 : Cannot remove duplicate data from the tableView

ios - 在 Cordova Build 上设置 Cordova StatusBar 插件默认值

iphone - 如果在 addSubView 之后调用,UIButton 不会移动

ios - 将参数传递给 addTarget :action:forControlEvents

ios - TWTRLogInButton(推特登录按钮)设置标题导致文字重叠

ios - finishWriting已被弃用:在iOS 6.0中首次被弃用

iOS SDK : Dismiss keyboard when a button gets clicked?