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; 
    } 
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容