HelloMoon
HelloMoon

Reputation:

Where's the difference between UIControlEventTouchDragOutside and UIControlEventTouchDragExit?

Both appear to have the exact same effect. They come both when the finger is far enough away from the control. The "bounds" is not really the criteria for UIControlEventTouchDragExit. It gets fired only if it's far away enough...

Upvotes: 3

Views: 2422

Answers (3)

Geri Borbás
Geri Borbás

Reputation: 16628

.touchDragOutside is continous, while .touchDragExit is not.

.touchDragOutside gets called on every drag movement that happens outside bounds (similar to DragGesture.onChanged(_:)), while .touchDragExit gets called once as the drag leaves the bounds.

They both (!) get called only when the drag is initiated within the view.

In addition, they are only fired when the finger is "far away" (~70 pt) from the control. They won't get fired as soon as the finger leaves the bounds (same goes .touchUpOutside). They seem to be designed for the users to deliberately cancel ongoing touches.

Upvotes: 0

walkingbrad
walkingbrad

Reputation: 1744

I came here looking for the same thing and the answer from eOgas did not seem accurate. I did my own test case and here are my results for those who want a detailed answer without having to test it for themselves:

UIControlEventTouchDragExit

  • gets called only once as the user leaves the control they pressed. Once the user breaks the 'magical boundary'* outside a UIButton (for instance) this event gets called once. If, while still dragging, the user drags back into the control and back out again, this event gets called once again. The reverse can apply to UIControlEventTouchDragEnter.

UIControlEventTouchDragOutside

  • gets called after UIControlEventTouchDragExit and gets called repeatedly every time the user drags their finger while still holding down the original touch that was used to enter the control. For those familiar with the touchesMoved method of UIView, it works similarly. The reverse can apply to UIControlEventTouchDragInside however this can obviously get called without having to leave the control first.

To understand or remember better, you can compare these events to a person leaving (and coming to) their house wherein they only exit the house once but then proceed to move outside repeatedly. Also, a person only enters their house once but then proceeds to move inside repeatedly.

*the extra space around a UIControl object that takes into consideration the user's potential for imprecise touches.

Upvotes: 13

eogas
eogas

Reputation: 109

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

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

It sounds like with UIControlEventTouchDragOutside is fired when the user touches just outside the bounds, regardless of whether or not the finger was ever within the bounds. UIControlEventTouchDragExit is only fired when the finger is dragged from within the bounds to outside the bounds.

So, UIControlEventTouchDragOutside would be used when resizing a control (an edge tap, then drag), whereas UIControlEventTouchDragExit would be used to move the control around (tap inside and drag).

Upvotes: 5

Related Questions