Here are two ways to achieve this. If you already have the UIView subclass that you are using, you can simply override the -touchesEnded:withEvent:
method in this subclass, for example:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *aTouch = [touches anyObject]; CGPoint point = [aTouch locationInView:self];
If you have not yet subclassed the UIView, and the view belongs to a view controller or the like, then you can use UITapGestureRecognizer, for example:
// when the view initially set up (in viewDidLoad, for example) UITapGestureRecognizer *rec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized:)]; [someView addGestureRecognizer:rec]; [rec release]; // elsewhere - (void)tapRecognized:(UITapGestureRecognizer *)recognizer { if(recognizer.state == UIGestureRecognizerStateRecognized) { CGPoint point = [recognizer locationInView:recognizer.view]; // again, point.x and point.y have the coordinates } }
Noah witherspoon
source share