정상적인 UITextView에서 특정 문자열에 탭 제스처를 할당 할 수 없습니다. UITextView에 대해 dataDetectorTypes를 설정할 수 있습니다. UIKit DataTypes Reference :
textview.dataDetectorTypes = UIDataDetectorTypeAll;
만 URL을 감지 할 경우에 할당 할 수있는,
textview.dataDetectorTypes = UIDataDetectorTypeLink;
이에 대한 자세한 내용은 설명서를 참조하십시오. 다음과 같이 확인, 당신의 의견을 바탕으로
: this에서
- (void)tapResponse:(UITapGestureRecognizer *)recognizer
{
CGPoint location = [recognizer locationInView:_textView];
NSLog(@"Tap Gesture Coordinates: %.2f %.2f", location.x, location.y);
NSString *tappedSentence = [self lineAtPosition:CGPointMake(location.x, location.y)];
//use your logic to find out whether tapped Sentence is url and then open in webview
}
사용 : 당신은 입도 등으로
- (NSString *)lineAtPosition:(CGPoint)position
{
//eliminate scroll offset
position.y += _textView.contentOffset.y;
//get location in text from textposition at point
UITextPosition *tapPosition = [_textView closestPositionToPoint:position];
//fetch the word at this position (or nil, if not available)
UITextRange *textRange = [_textView.tokenizer rangeEnclosingPosition:tapPosition withGranularity:UITextGranularitySentence inDirection:UITextLayoutDirectionRight];
return [_textView textInRange:textRange];
}
시도 할 수 있습니다 또한이 Documentation on UITextView
업데이트를 확인 as, UITextGranularitySentence, UITextGranularityLine 등을 확인하십시오.을 확인하십시오.210 여기.
링크를 표시하지만 제스처가 모든 textView에 반응합니다 –
예. 링크를 누르면 URL 스키마를 기반으로 해당 애플리케이션이 열립니다. – iDev
그래, UITapGesture가있는 사파리에서 URL을 열면 내 UIWebView에 열어두기를 바랬다 –