Reputation: 2609
I am trying to decrease the touch area of an UIButton. Is that even possible? When the user touches on the button and drags his touch outside the buttton the touch event should stop immediately when the graphic of the button ends. Unfortunately the area is much bigger than the actual graphic. I found a lot things on how to increase the area but not how to make it smaller.
Thanks for your help.
Upvotes: 3
Views: 893
Reputation: 4463
I came up one solution. You can subclass UIButton
and override touchesMoved:
so that it recognize the touch to be ended if it was outside of the button. Here is my snippet.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
if(!CGRectContainsPoint(self.bounds, touchPoint))
{
[super touchesEnded:touches withEvent:event];
}
else
{
[super touchesMoved:touches withEvent:event];
}
}
The drawback of this is that if you go out of the button and come back again, the button will not become active. But otherwise, I think it should work fine.
Upvotes: 1