i need to get the coordinate position from touching a view. The view i touch is UITextview. THe hierarchy of the view is UIViewController -> UITextview. I think i can use locationInView
method to get that coordinate. I know that UITextview have some delegate methods, so i think i have to use textViewShouldBeginEditing
delegate method to call the locatioInView.
This is my code snippet
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView {
NSSet *touches;
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:textView];
NSLog(@"currentTouchPosition: x=%f, y=%f", currentTouchPosition.x, currentTouchPosition.y);
return YES;
}
my problem is, the currentTouchPosition always have 0 value in x and y. I dont know what's wrong with that code. Can somebody tell me???
thank you
UPDATE Finally i've solved this problem. I have use UITapGestureRecognizer in viewDidLoad and then get the tap location using the same method i was use in textViewShouldBeginEditing. This is the code i've made :
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
tap.delegate=self;
[self.textView addGestureRecognizer:tap];
tap.numberOfTapsRequired = 1;
[tap release];
}
and this is the handleTapFrom :
- (void)handleTapFrom:(UITapGestureRecognizer *)recognizer {
locationTap = [recognizer locationInView:self.textView];
}