ios UIButton 事件。有什么不同?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11389915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:11:12  来源:igfitidea点击:

UIButton events. What's the difference?

objective-ciosuibuttonibaction

提问by Protheus

I've encountered a problem where my button should remain "pressed down" while it shows popover called from it. Popover is selector for some filter and filter is shown on button itself. When I tap on it and it shows popover it becomes deselected no matter what.

我遇到了一个问题,当它显示从它调用的弹出窗口时,我的按钮应该保持“按下”状态。Popover 是某些过滤器的选择器,过滤器显示在按钮本身上。当我点击它并显示弹出窗口时,无论如何它都会被取消选择。

I think I have to redefine it's behavior on touch event and make it respond not to standart touch up inside. Then I wondered what are other events responsible for? But I couldn't find events list in iOS library and in StackOverflow are only questions about incorrect behavior of touch up insideor touch down.

我想我必须重新定义它在触摸事件上的行为,并使其不响应标准touch up inside。然后我想知道其他事件负责什么?但是我在 iOS 库中找不到事件列表,在 StackOverflow 中只是关于touch up insideor 的不正确行为的问题touch down

So what's the difference betweeen touch events?

那么触摸事件之间有什么区别呢?

  1. touch cancel - when you touch button but move your finger away and it remains deselected?
  2. touch down - right on tap.
  3. touch down repeat ??
  4. touch drag enter ??
  5. touch drag exit ??
  6. touch drag inside ??
  7. touch drag outside ??
  8. touch up inside - when you tap and release button remaining in it's bounds . It changes UIButtons state to Normal.
  9. touch up outside - when you tap and release button leaving it's bounds ?
  1. 触摸取消 - 当您触摸按钮但将手指移开并保持取消选择时?
  2. 触地 - 轻按。
  3. 向下重复??
  4. 触摸拖动进入??
  5. 触摸拖动退出??
  6. 触摸拖动里面??
  7. 触摸拖到外面??
  8. 触摸内部 - 当您点击并释放按钮时,保持在其边界内。它将 UIButtons 状态更改为 Normal。
  9. 在外面触摸 - 当你点击并释放按钮离开它的界限时?

other IBActions are not sent by UIButton, right? Also how those events change UIButton's appearance? Like highlightedor selected?

其他 IBActions 不是由 UIButton 发送的,对吗?还有这些事件如何改变 UIButton 的外观?喜欢highlighted还是selected

I'd appreciate a link on good article about IBActions, because I couldn't find it.

我很感激关于 IBActions 的好文章的链接,因为我找不到它。

回答by Protheus

From Apple's doc for UIControlEvents:

来自Apple 的文档UIControlEvents

  1. UIControlEventTouchCancel

    A system event canceling the current touches for the control.

  2. UIControlEventTouchDown

    A touch-down event in the control.

  3. UIControlEventTouchDownRepeat

    A repeated touch-down event in the control; for this event the value of the UITouch tapCount method is greater than one.

  4. UIControlEventTouchDragEnter

    An event where a finger is dragged into the bounds of the control.

  5. UIControlEventTouchDragExit

    An event where a finger is dragged from within a control to outside its bounds.

  6. UIControlEventTouchDragInside

    An event where a finger is dragged inside the bounds of the control.

  7. UIControlEventTouchDragOutside

    An event where a finger is dragged just outside the bounds of the control.

  8. UIControlEventTouchUpInside

    A touch-up event in the control where the finger is inside the bounds of the control.

  9. UIControlEventTouchUpOutside

    A touch-up event in the control where the finger is outside the bounds of the control.

  1. UIControlEventTouchCancel

    取消控件的当前触摸的系统事件。

  2. UIControlEventTouchDown

    控件中的触摸事件。

  3. UIControlEventTouchDownRepeat

    控件中重复的触地事件;对于此事件,UITouch tapCount 方法的值大于 1。

  4. UIControlEventTouchDragEnter

    将手指拖入控件边界的事件。

  5. UIControlEventTouchDragExit

    将手指从控件内拖动到其边界外的事件。

  6. UIControlEventTouchDragInside

    在控件边界内拖动手指的事件。

  7. UIControlEventTouchDragOutside

    手指被拖动到控件边界之外的事件。

  8. UIControlEventTouchUpInside

    控件中手指位于控件边界内的触摸事件。

  9. UIControlEventTouchUpOutside

    控件中手指超出控件边界的触摸事件。

回答by Dave G

Listed in, what I would consider, order of common use/likelihood of occurrence for a normal button:

列出,我会考虑,普通按钮的常见使用顺序/发生的可能性:

UIControlEventTouchDown: The user tapped the button. This fires on the finger/stylus making contact.

UIControlEventTouchDown:用户点击按钮。这会在接触的手指/手写笔上触发。

UIControlEventTouchUpInside: The user tapped the button. This fires on the finger/stylus contact pulled back away from the screen.

UIControlEventTouchUpInside:用户点击按钮。这会在手指/手写笔接触点从屏幕上拉回时触发。



Useful for sliders and drag events like moving a component around. The below are in order of occurrence:

对于滑块和拖动事件(如移动组件)很有用。以下按出现顺序排列:

UIControlEventTouchDragInside: Triggered as the finger drags into the button area.

UIControlEventTouchDragInside:当手指拖入按钮区域时触发。

UIControlEventTouchDragExit: Triggered during a drag motion. It is called only once, as the users finger/stylus leaves the bounds of the button.

UIControlEventTouchDragExit:在拖动动作期间触发。当用户的手指/手写笔离开按钮的边界时,它只被调用一次。

UIControlEventTouchDragOutside: Triggered during a drag motion, after 'UIControlEventTouchDragExit', and is called continuously, as long as the original touch continues.

UIControlEventTouchDragOutside:在拖动动作期间触发,在 'UIControlEventTouchDragExit' 之后,并持续调用,只要原始触摸继续。

UIControlEventTouchUpOutside: This is simply the finger/stylus being lifted BUT only if the finger/stylus is no longer within the bounds of the button. The important thing (and probably obviously) to call out is that the touch had to have been within the button at some point to associate this event with the button.

UIControlEventTouchUpOutside:这只是手指/手写笔被抬起,但仅当手指/手写笔不再位于按钮的边界内时。需要指出的重要事情(可能很明显)是触摸必须在某个时间点位于按钮内才能将此事件与按钮相关联。

Note: My understanding is that the above can be helpful for:

注意:我的理解是上述内容有助于:

  1. Sliders: as you might expect the touch may have been intentional but because of the quick swipe action, their finger movement may be sloppy and lift up outside of the slider area.
  2. Moving components around, as when you push things around a screen you want the movement to happen when the finger/stylus touches the border of the component/object.
  1. 滑块:正如您预期的那样,触摸可能是有意的,但由于快速滑动动作,它们的手指移动可能会很松散并抬升到滑块区域之外。
  2. 四处移动组件,就像在屏幕上推东西一样,您希望在手指/手写笔接触组件/对象的边界时发生移动。


Other events:

其他活动:

UIControlEventTouchCancel: Something out of the user's control is cancelling their touch action. Think of this as something "going wrong" on the phone side of things.

UIControlEventTouchCancel:用户无法控制的事情正在取消他们的触摸操作。将此视为电话方面的“出错”。

UIControlEventTouchDownRepeat: Want to detect when your user is mad and tapping a button furiously? Want to detect if they're still in Windows mode and are trying to "double click"? Or maybe you designed a button to do something different if they tap twice. This event helps with all of those!

UIControlEventTouchDownRepeat:想要检测您的用户何时生气并疯狂点击按钮?想要检测他们是否仍处于 Windows 模式并尝试“双击”?或者,也许您设计了一个按钮,如果他们点击两次,则可以执行不同的操作。本次活动对所有这些都有帮助!



References:

参考:

SO 1: Dif between UIControlEventTouchDragOutside and UIControlEventTouchDragExit

SO 1:区分 UIControlEventTouchDragOutside 和 UIControlEventTouchDragExit

SO 2: What is UIControlEventTouchCancel?

SO 2:什么是 UIControlEventTouchCancel?