【发布时间】:2014-04-18 05:52:22
【问题描述】:
在 iOS 7 应用程序中,我有一个带有链接的 UITextView,但点击该链接不会触发。它只会对尴尬的“点击并按住”做出反应。我希望它在用户点击它时立即响应,就像UIWebView 链接点击的工作原理一样。这是我的设置:
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."];
[text addAttribute:NSLinkAttributeName value:@"myurl://tapped" range:NSMakeRange(6, 16)];
self.textView.attributedText = text;
self.textView.editable = NO;
self.textView.delaysContentTouches = NO;
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange
{
if ([[URL scheme] isEqualToString:@"myurl"])
{
// Handle tap
return NO;
}
return YES;
}
shouldInteractWithURL 方法的 Apple 文档指出:“如果用户点击或长按 URL 链接,文本视图会调用此方法”。长按可以工作,但点按似乎不起作用。
有谁知道如何让这个立即响应?
【问题讨论】:
-
链接点击识别延迟在iOS9中仍然发生:((((((
标签: ios objective-c uitextview