繁体   English   中英

UITextView链接无法点击iOS 8

[英]UITextView link not clickable iOS 8

我遵循这个: UILabel和NSLinkAttributeName:链接不可点击UITextView链接是可点击的,但当我点击它时,Safari不会打开但无济于事。

我有 :

uitextView.attributedText = ... some attributed string "http://google.com" ...

启用“链接检测”,“可选”和“启用用户交互”。 “可编辑”已禁用。

我还实现了UITextViewDelegate

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)url inRange:(NSRange)characterRange
{

    return YES;
}

但是,链接显示为蓝色,但是当我点击时,没有任何反应。

我遇到过同样的问题。 什么都没有帮助。

问题是,我将UITextView添加到ScrollView,然后使用sizeToFit

例如:我有view.frame (0,0,320,440)。 和ScrollView contentSize(0,0,320,1000)和view.frame中的链接view.frame工作,但是当你向下滚动时 - 不是。

当我向下滚动并点击UITextView时,我试图查看正在选择的视图。 我添加了UITapGestureRecognizers并发现当我在UITextView的边界中点击self.view框架的边界时,它点击了UITextView。 但是当我向下滚动时 - 水龙头会在ScrollView上识别为点按。 换句话说,它就像是self.view界限的UITextView剪辑框架。

编辑:我发现了问题:

我有View - ScrollView - ContentView - Elements层次结构。 所以有一段时间,当ScrollView比ContentView大时,只能在ContentView的边界中点击链接。 为了解决这个问题,我删除了ContentView并将所有元素放到ScrollView中。 希望这个答案会有所帮助:)

尝试采取这种方法:

NSString *clickMe = [NSString stringWithFormat:@"%@", word];
    NSMutableAttributedString * str2 = [[NSMutableAttributedString alloc] initWithString:word];
    [str2 addAttribute: NSLinkAttributeName value:[NSURL URLWithString:[NSString stringWithFormat:@"https://twitter.com/%@",linkWord]] range:NSMakeRange(0, clickMe.length)];

    // replace with link
    [YourAttributedString replaceCharactersInRange:wordRange withAttributedString:str2];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM