0

I'm using this method, but it works only for my UIView subclass. If I tap on UITextView or UIButton or on any other object it's not display coordinates. How to get coordinates of tap on UITextView? And why this happening?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *userTouch = [[event allTouches] anyObject];
    CGPoint currentPos = [userTouch locationInView:self.view];
    NSLog(@"Coordinates: (%f,%f)", currentPos.x, currentPos.y);
}
Konstantin Cherkasov
  • 3,243
  • 2
  • 18
  • 22

1 Answers1

0

Add this code in ViewDidLoad method,

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapRecognized:)];
singleTap.numberOfTapsRequired = 1;
[self.textView addGestureRecognizer:singleTap];

Implement above method

-(void)singleTapRecognized:(id)sender{
    CGPoint tapPoint = [sender locationInView:self.textView];
    NSLog(@"Coordinates: (%f,%f)", tapPoint.x, tapPoint.y);
}
isuru
  • 3,385
  • 4
  • 27
  • 62
karthika
  • 4,085
  • 3
  • 21
  • 23