molon / MLLabel

UILabel replacement with TextKit. Support link and expression.
MIT License
723 stars 115 forks source link

当MLLinklabel添加单击事件UITapGestureRecognizer的时候,导致didClickLink失效 #83

Closed czl0325 closed 6 years ago

czl0325 commented 6 years ago

你好,类似微信朋友圈回复评论,点击评论者名字可以促发didClickLink:linkText:linkLabel:,然后点击整条评论,希望促发回复评论的事件,但是如果在当MLLinklabel添加单击事件UITapGestureRecognizer的时候,就会导致didClickLink:linkText:linkLabel:失效了,无奈我添加了一个- (void)didClickOther:(MLLinkLabel*)linkLabel;事件,在下面调用,让他点击其他地方响应。

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (self.activeLink) {
        NSString *linkText = [self.text substringWithRange:self.activeLink.linkRange];

        //告诉外面已经点击了某链接
        if (self.activeLink.didClickLinkBlock) {
            self.activeLink.didClickLinkBlock(self.activeLink,linkText,self);
        }else if (self.didClickLinkBlock) {
            self.didClickLinkBlock(self.activeLink,linkText,self);
        }else if(self.delegate&&[self.delegate respondsToSelector:@selector(didClickLink:linkText:linkLabel:)]){
            [self.delegate didClickLink:self.activeLink linkText:linkText linkLabel:self];
        }

        [self performSelector:@selector(setActiveLink:) withObject:nil afterDelay:self.activeLinkToNilDelay];
    } else {
        if(self.delegate&&[self.delegate respondsToSelector:@selector(didClickOther:)]){
            [self.delegate didClickOther:self];
        }
        [super touchesEnded:touches withEvent:event];
    }
}

不知道作者有没有更好的方法?如果有麻烦更新代码下。

molon commented 6 years ago

https://github.com/molon/MLLabel/issues/33