IOS: inconsistent behavior with UIButton event UIControlEventTouchUpOutside

I want to get dual functionality from UIButton.

When the user touches the button, I want him to immediately call behavior A

But if the user then drags his finger outside the button before releasing it, I would also like to trigger behavior B. After release.

So,

[presetButton addTarget: self action: @selector( presetButtonHit: ) forControlEvents: UIControlEventTouchDown ]; [presetButton addTarget: self action: @selector( presetButtonSwipe: ) forControlEvents: UIControlEventTouchUpOutside ]; 

As a test case, I will simply write “A” or “B” from the appropriate action methods.

A always gets right.

However, B is sporadic. I can methodically skip my fingers, drag it out of the button, wait a second, and release it. And this is usually normal. Alternatively, if I make a quick click, it will most likely fire. But still 50-50.

I have a UIView with a background image and six buttons.

What can I do to track this?

I would rather get to the bottom of the mess than manually tracking up and down touches; but if I have to do this, is there any clean way? From what I see, it will be a royal PITA, and I will need to find out if the paths go up / down before my button touches up / down, gets there, sets the flags, etc.

+4
source share
1 answer

This is a duplicate. UIButton's strange behavior: is this normal? but I recommend keeping it because the title of the question is well worded.

When my finger drops on the button, the image darkens

when I pull my finger away, when I skip an invisible circle with a transparent centimeter and more outside the frame of the button, the image returns to its original color

This is a typical behavior for "cancel touch by moving your finger far enough before releasing"

if you release your finger inside this zone, it will shoot inward. sim for outside.

It looks as if Apple did not expect anyone to use these methods to get dual functionality from UIButton.

Now, is there any easy way to catch the XY touch coordinates inside the action. the action simply gets the id of the button that was clicked.

But here is an elegant way:

http://sree.cc/iphone/handling-touche-events-for-uibuttons-in-iphone

UIControl has methods to detect start / move / stop drag and drop. You can override them and get the screen coordinates.

+2
source

All Articles