UITextView链接点击识别被延迟 [英] UITextView link tap recognition is delayed

查看:78
本文介绍了UITextView链接点击识别被延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 7应用中,我有一个UITextView,其中带有链接,但是点击该链接不会触发.它仅响应尴尬的轻按并按住".我希望它在用户点击时立即响应,例如UIWebView链接点击的工作方式.这是我的设置:

In an iOS 7 app, I have a UITextView with a link in it, but tapping the link doesn't fire. It only responds to an awkward "tap and hold". I want it to respond as soon as a user taps on it, like how a UIWebView link tap works. Here is my setup:

- (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链接,则文本视图将调用此方法".长按有效,但轻按似乎无效.

The Apple Documentation for the shouldInteractWithURL method states: "The text view calls this method if the user taps or long-presses the URL link". The long-press is working, but the tap doesn't seem to work.

有人知道如何让它立即响应吗?

Does anyone know how to get this to respond immediately?

推荐答案

UITextView是否可选?尝试:

self.textView.selectable = YES;

我开始认为,长按是将其触发的唯一方法,这与苹果所说的相反.选中此链接,也许会有所帮助.

I'm starting to think that maybe a long-press is the only way to fire it contrary to what apple says. Check this link, maybe it will help.

这篇关于UITextView链接点击识别被延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆