Checking if a touch is withing a UIButton's bounds.
Posted
by Joshua
on Stack Overflow
See other posts from Stack Overflow
or by Joshua
Published on 2010-04-18T12:19:50Z
Indexed on
2010/04/18
12:23 UTC
Read the original article
Hit count: 339
cocoa-touch
|uikit
I am trying to make an if
statement which will check whether the users touch is within a UIButton's bounds. I thought this would be an easy affair as UIButton is a subclass of UIView, however my code doesn't seem to work.
This is the code I have been using.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *array = [touches allObjects];
UITouch *specificTouch = [array objectAtIndex:0];
currentTouch = [specificTouch locationInView:self.view];
if (CGRectContainsPoint(but.bounds, currentTouch)) {
//Do something is in bounds.
}
//Else do nothing.
}
© Stack Overflow or respective owner