你可以尝试使用
UITapGestureRecognizer
它可以解决你的问题
UITapGestureRecognizer *rec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(userTapped:)];
[self addGestureRecognizer:rec];
- (void)userTapped:(UITapGestureRecognizer *)recognizer
{
if(recognizer.state == UIGestureRecognizerStateRecognized)
{
CGPoint point = [recognizer locationInView:recognizer.view];
// point.x and point.y touch coordinates
NSLog("%lf %lf", point.x, point.y);
// here you could call your method or add the new view controller which you want
[self addNewViewController];
}
}
为了表达观点
touchesEnded
您应该使用CGPoint
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *aTouch = [touches anyObject];
CGPoint point = [aTouch locationInView:self];
// point.x and point.y touch coordinates
NSLog("%lf %lf", point.x, point.y);
}