Reputation: 7103
I have a draggable UIButton
in my app. I want to be able to fire an action on UIControlEventTouchUpInside
. That works fine. However, I don't want it to fire if the user drags the button and then lifts their finger from the screen (which at the moment is firing the action dependent on UIControlEventTouchUpInside
).
Is there any way to set my button's touch event listeners so that an event is fired on TouchUpInside but only if the button wasn't being dragged?
Upvotes: 0
Views: 189
Reputation: 1199
You would have to subclass a UIButton, then overwrite:
- touchesMoved
- touchesEnded
In Moved method, set the move flag to true, in the Ended method, check for that flag. If true, call super. Else, redirect it to touchDidCanceled.
Btw, it would be better if you show us how you make a draggable button, with gesturerecognizer?
Upvotes: 2
Reputation: 1523
You can do this also , take UIButton as a subView of UIView .
now set touchUpInside for uibutton and add panGuesture on UIView .
that's how the touch up inside and dragging never mess up.
Upvotes: 0