美文网首页
YYLabel高亮点击事件与tap手势冲突解决

YYLabel高亮点击事件与tap手势冲突解决

作者: Queen_BJ | 来源:发表于2022-03-30 14:22 被阅读0次

在手势代理方中,判断YYLabel富文本中是否有高亮对象

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ([touch.view isKindOfClass:[YYLabel class]]){
      YYLabel *label = (YYLabel *)touch.view;
        NSAttributedString *attributedString = label.attributedText;
        NSUInteger index = [label.textLayout textRangeAtPoint:[touch locationInView:label]].start.offset;
// 判断当前文本上是否有点击事件
        YYTextHighlight *hl = [attributedString yy_attribute:YYTextHighlightAttributeName atIndex:index]; 
// 判断是否有高亮对象
        return hl ? NO : YES; 
    } 
}

相关文章

网友评论

      本文标题:YYLabel高亮点击事件与tap手势冲突解决

      本文链接:https://www.haomeiwen.com/subject/zfzijrtx.html