How can I click a link in the UITextView and get the position of the 'tap' at the same time

StackOverflow https://stackoverflow.com/questions/22533825

Вопрос

I have added some links to my UITextView using NSAttributedString,and I want to show user a 'note' when they click the link.The problem is I don't know how to get the position of the tap where user tap to open the link.

Это было полезно?

Решение

override hitTest:withEvent method

signature

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

Above method is supplied with CGPoint which is the location of touch.Create a CGPoint class property and store the touch-location in it.

@property (nonatomic,assign) CGPoint previousTouch;

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
   self.previousTouch = point;
   return [super hitTest:point withEvent:event];
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top