Vad
Vad

Reputation: 3740

How to Better Drag a UIButton? UIButton UIControlEventTouchUpInside Event Is Not Called

My draggable button is using these events to be dragged:

[button addTarget:self action:@selector(beganDragging:)
                     forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(wasDragged:withEvent:)
                     forControlEvents:UIControlEventTouchDragOutside | UIControlEventTouchDragInside];
[button addTarget:self action:@selector(exitDragging:)
                     forControlEvents:UIControlEventTouchUpInside];

It's straight forward above. Method wasDragged adjusts the center of the UIButton to the UITouch location. However, there are cases when I end up with button being hung (normally it snaps to grid after finger release) because UIControlEventTouchUpInside is never called!

How? Let's say I start dragging a button and while holding it I make a screenshot (Power+Home). When I release the button no events are ever called (i.e. UIControlEventTouchUpInside). Therefore, my button is stuck and not snapping to grid which is in method exitDragging

Any light how to make sure exitDragging always runs?

Upvotes: 2

Views: 341

Answers (1)

Mundi
Mundi

Reputation: 80265

Maybe it is easier using the UIView APIs with touchesBegan, touchesEnded etc.

It seems you are anyway not using the UIButton functionalities. I think that managing a drag with the target mechanism of UIButton is not what it was intended for.

Upvotes: 1

Related Questions