【问题标题】:Detecting touches on an underlying UITableViewCell and taps in attributed text of a UITextview检测对底层 UITableViewCell 的触摸并点击 UITextview 的属性文本
【发布时间】:2014-06-18 18:21:51
【问题描述】:

我使用UITextView 附加到UITableViewCell 的配置如下所示:

cell.topicAndDescriptionTextView = [[UITextView alloc] initWithFrame:frame];
cell.topicAndDescriptionTextView.tag = 1;
cell.topicAndDescriptionTextView.attributedText = attrText;    
cell.topicAndDescriptionTextView.scrollEnabled = NO;
cell.topicAndDescriptionTextView.editable = NO;
cell.topicAndDescriptionTextView.textContainer.lineFragmentPadding = 0;
cell.topicAndDescriptionTextView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0);
cell.topicAndDescriptionTextView.backgroundColor =[UIColor clearColor];
[cell.topicAndDescriptionTextView setUserInteractionEnabled:YES];
cell.topicAndDescriptionTextView.dataDetectorTypes = UIDataDetectorTypeAll;

现在我想使用文本工具包功能来检测对我的属性文本 (http://www.raywenderlich.com/48001/easily-overlooked-new-features-ios-7#textViewLinks) 和 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 中的自定义链接的点击,以在客户点击 UITableViewCell 中没有自定义的某处时识别向下钻取链接。

不幸的是 [UITextView setUserInteractionEnabled:YES] 让 textview 吞下所有的触摸。实现这一目标的最佳方法是什么?我想编写一个自定义的UITextView 类,并使用UITextView 代表,但是我如何才能确定超类是否已经处理了链接上的新闻并阻止向下钻取?

谢谢,

一月

【问题讨论】:

标签: ios objective-c uitableview uitextview textkit


【解决方案1】:

我会尝试覆盖 hitTest 并且仅在返回的视图是用于链接按钮的视图时才返回命中视图。在其他情况下返回零。然后将触摸传递给表格视图,滚动继续工作。

【讨论】:

  • 谢谢!将对此进行测试并在我运行时提供反馈!
【解决方案2】:

我找到了解决方案。我创建了我的自定义 UITextView 类并覆盖了 touchesBegan。只有在 UITextView 中没有点击链接时才会调用 Touches Began。我玩过hitTest,但一直调用hitTest,我无法确定UITextView中是否触摸了链接。

【讨论】:

    猜你喜欢
    • 2013-10-20
    • 2018-04-21
    • 2016-02-13
    • 1970-01-01
    • 2014-04-13
    • 2011-10-01
    • 1970-01-01
    相关资源
    最近更新 更多