长时间在UITextView的单词中获取单词

现在我已经在UITextView中检测到很长时间了

- (void)viewDidLoad { [super viewDidLoad]; UILongPressGestureRecognizer *LongPressgesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressFrom:)]; [[self textview] addGestureRecognizer:LongPressgesture]; longPressGestureRecognizer.delegate = self; } - (void) handleLongPressFrom: (UISwipeGestureRecognizer *)recognizer { CGPoint location = [recognizer locationInView:self.view]; NSLog(@"Tap Gesture Coordinates: %.2f %.2f", location.x, location.y); } 

现在,我应该怎么做才能得到长时间的单词的内容,并得到这个单词的准备,以显示PopOver?

这个函数将返回UITextView中给定位置的单词。

 +(NSString*)getWordAtPosition:(CGPoint)pos inTextView:(UITextView*)_tv { //eliminate scroll offset pos.y += _tv.contentOffset.y; //get location in text from textposition at point UITextPosition *tapPos = [_tv closestPositionToPoint:pos]; //fetch the word at this position (or nil, if not available) UITextRange * wr = [_tv.tokenizer rangeEnclosingPosition:tapPos withGranularity:UITextGranularityWord inDirection:UITextLayoutDirectionRight]; return [_tv textInRange:wr]; }