bfeher / BFPaperButton

iOS Buttons inspired by Google's Paper Material Design.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TouchUpInside event is fired even if you touch up outside the button

jerydarkside opened this issue · comments

Hi,

I noticed that if you "touch up" outside of the button (as if you want to cancel your touch), the "TouchUpInside" event is sometimes fired.

It happens if you "touch up outside" too close to the button (for example, in an area the growing disk would cover if it wasn't clipped).

Is there a way to limit the "touch up inside" event to the area of the visible button?

Sincerely,

Jery

Edit: I'm not sure but it may be a duplicate of issue #3, in that case, sorry for that.

Hi Jery,

While I'm not sure how to modify the way that Apple calculates a button's tappable zone, I can offer you a workaround solution. In your event handler for UIControlEventTouchUpInside, you can check to see if the location of the touchUpInside event is actually within the bounds of the button:

[myButton addTarget:self action:@selector(buttonWasPressed:event:) forControlEvents:UIControlEventTouchUpInside];
//...
- (void)buttonWasPressed:(UIButton *)sender event:(UIEvent *)event
{
    CGPoint location = [[[event allTouches] anyObject] locationInView:sender];

    if (!CGRectContainsPoint(sender.bounds, location)) {
        // Outside of bounds, so ignore:
        return;
    }
    // Inside our bounds, so continue as normal:
}

I hope that helps!

Hi!

Thank you for this workaround. It is very simple and works as expected!

Sincerely,

Jery