【问题标题】:TTTAttributedLabel link is styled and has UILongPressGestureRecognizer but doesn't have UITapGestureRecognizerTTTAttributedLabel 链接已设置样式并具有 UILongPressGestureRecognizer 但没有 UITapGestureRecognizer
【发布时间】:2016-10-12 09:17:32
【问题描述】:

在我的项目中,我已将 TTTAttributedLabel 添加到 IB 的视图中并添加了一个链接。

我已经查看了关于 SO 的类似问题(例如 this 和 this),但没有运气。

它显示正确,链接的样式符合预期。但是当我尝试点击链接时,没有调用-(void)attributedLabel:didSelectLinkWithURL:。但是,如果我使用长按而不是 -(void)attributedLabel:didLongPressLinkWithURL:atPoint: 按预期触发。所以我确定代表正在工作。似乎标签甚至没有tapGestureRecognizer

(lldb) po label.gestureRecognizers
<__NSSingleObjectArrayI 0x60800000ee60>(
<UILongPressGestureRecognizer: 0x7f88f6c5d480; state = Began; view = <TTTAttributedLabel 0x7f88f6f8ada0>; target= <(action=longPressGestureDidFire:, target=<TTTAttributedLabel 0x7f88f6f8ada0>)>>
)

代码如下:

RFStaticAttributedLabelFormView *labelView = [RFStaticAttributedLabelFormView new];
labelView.staticLabel.userInteractionEnabled = YES;
labelView.staticLabel.delegate = self;
NSString *text = RFLocalized(@"TXT_FINES_SEARCH_FNS");
[labelView.staticLabel setText:text afterInheritingLabelAttributesAndConfiguringWithBlock:nil];
NSRange r = [text rangeOfString:RFLocalized(@"TXT_FINES_SEARCH_FNS_LINK")];
[labelView.staticLabel addLinkToURL:[NSURL URLWithString:@"http://www.google.com"] withRange:r];

RFStaticAttributedLabelFormView 是一个视图,从 XIB 实例化。

不知道从这里去哪里。

【问题讨论】:

    标签: ios uigesturerecognizer tttattributedlabel


    【解决方案1】:

    我创建了一个带有单个 TTTAttributedLabel 的全新项目。在我连接委托方法后,一切都开始按预期工作,包括单击。我检查了标签上的手势识别器——结果发现它也没有点击识别器,只有长按识别​​器。

    之后,我查看了我的原始项目并找到了问题的根源。层次结构中的主视图有另一个点击手势识别器,它正在拦截所有点击事件。我已经添加了这一行:

    tap.cancelsTouchesInView = NO;
    

    TTTAttributedLabel 中的链接开始正常工作。希望这个答案可以帮助有类似问题的人。

    【讨论】:

      【解决方案2】:

      你是否实现了&lt;TTTAttributedLabelDelegate&gt;协议的委托方法-(void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url;?

      【讨论】:

      • 是的,当然。我在那里添加了一条日志消息,所以我确定它没有被调用。
      猜你喜欢
      • 2015-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-09
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多