使用YYLabel时遇到点击事件被延迟

在使用YYLabel时

- (YYLabel *)repeatLab{
    if(!_repeatLab){
        _repeatLab = [[YYLabel alloc] initWithFrame:CGRectMake(0 , 100 , ScreenWidth-20, 20)];
        _repeatLab.textColor = TITLE_COLOR;
        _repeatLab.userInteractionEnabled = YES;
        NSString *str = @"重新发送这个按钮哦";
        NSMutableAttributedString *attrStr =[[NSMutableAttributedString alloc] initWithString:str];
        attrStr.yy_font = SDFONT;
        attrStr.yy_color =  [UIColor colorWithHexString:@"808080" alpha:1];
        attrStr.yy_alignment = NSTextAlignmentRight;
        
        [attrStr yy_setTextHighlightRange:NSMakeRange(0, 4) color:[UIColor blueColor] backgroundColor:[UIColor redColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            DLog(@"点击重新发送");
            [MessageView showMessage:@"点击重新发送"];
        }];
        self.repeatLab.attributedText =attrStr;
    }
    return _repeatLab;
}

然后在viewDidLoad里 [self.view addSubview:self.repeatLab];
是不是感觉很完美,但是当你开心的点击重新发送时,你发现点击事件不响应,然后你以为你哪错了,然后你查看源代码后发现没有错啊,于是你有重复的点了几次,最后发现点击事件延迟了,按住不放停几秒后才会响应点击事件
然后你一点一点查看代码
最后发现[self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick)]];
然后注释掉发现延迟取消了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容