在使用YYLabel時
- (YYLabel *)repeatLab{
if(!_repeatLab){
_repeatLab = [[YYLabel alloc] initWithFrame:CGRectMake(0 , 100 , ScreenWidth-20, 20)];
_repeatLab.textColor = TITLE_COLOR;
_repeatLab.userInteractionEnabled = YES;
NSString *str = @"重新發(fā)送這個按鈕哦";
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(@"點擊重新發(fā)送");
[MessageView showMessage:@"點擊重新發(fā)送"];
}];
self.repeatLab.attributedText =attrStr;
}
return _repeatLab;
}
然后在viewDidLoad里 [self.view addSubview:self.repeatLab];
是不是感覺很完美,但是當你開心的點擊重新發(fā)送時,你發(fā)現(xiàn)點擊事件不響應(yīng),然后你以為你哪錯了,然后你查看源代碼后發(fā)現(xiàn)沒有錯啊,于是你有重復(fù)的點了幾次,最后發(fā)現(xiàn)點擊事件延遲了,按住不放停幾秒后才會響應(yīng)點擊事件
然后你一點一點查看代碼
最后發(fā)現(xiàn)[self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick)]];
然后注釋掉發(fā)現(xiàn)延遲取消了