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

在手势代理方中,判断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手势冲突解决)