我正试着从水龙头里得到一个字.以下函数sender
来自UIGesture
于UITextView
句子.
- (IBAction)printWordSelected:(id)sender {
NSLog(@"Clicked");
CGPoint pos = [sender locationInView:self.view];
UITextView *_tv = sentence;
NSLog(@"Tap Gesture Coordinates: %.2f %.2f", pos.x, pos.y);
//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];
NSLog(@"WORD: %@", [_tv textInRange:wr]);
}
Run Code Online (Sandbox Code Playgroud)
这是我已经拥有的,但它将单词输出为NULL
归档时间: |
|
查看次数: |
3149 次 |
最近记录: |