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.
}