当用户在我的应用程序中点击并按住 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/