When you press a UIButton, if you keep holding it while dragging your finger outside of its bounds, there's a certain distance that you can move you finger until the button's state is not "highlighted" anymore.
Essentially, you can press a button, move your finger outside of it, release it, and the button will still fire, even though your finger wasn't on it when it was released.
Is there any way to prevent this behavior? I want buttons to be "released" as soon as you're outside of them.
The
UIControlEventyou are looking for isUIControlEventTouchUpInside- It works when touch is inside of the bound.For more details check this URL:
https://developer.apple.com/documentation/uikit/uicontrolevents
https://developer.apple.com/documentation/uikit/uicontrolevents/uicontroleventtouchupinside?language=objc