给YYlabel做了点击事件,父view上加了一个tap手势,然后YYlabel的事件就不执行了。希望可以解决下这个手势冲突。
Activity
hydyy commentedon Nov 27, 2015
确实 我也遇到了。
ibireme commentedon Nov 27, 2015
配置一下:
gesture.cancelsTouchesInView = NO。wy19901227 commentedon Nov 27, 2015
yes还是no 默认是yes
发自我的 iPhone
ibireme commentedon Nov 27, 2015
NO
LCcccccc commentedon Sep 11, 2016
@ibireme 我是在YYLabel上加了highlightTapAction,父view上加了一个tapGesture, cancelsTouchesInView设为NO后,再点击一下highlight文本时,会先触发父view的事件,再触发highlightTapAction,请问要怎样设置才能只触发highlightTapAction而不触发父view的事件呢?谢谢!
zhangyuhan18 commentedon Dec 11, 2017
@LCcccccc 你好,想请教一下这个问题解决了吗“父view上加了一个tapGesture, cancelsTouchesInView设为NO后,再点击一下highlight文本时,会先触发父view的事件,再触发highlightTapAction“
liycoding commentedon Aug 20, 2018
#pragma mark - UIGestureRecognizerDelegate 请在需要有link事件的地方设置YYTextHighlight 否则不设置YYTextHighlight
(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
BOOL isCanRecognize = YES; //是否能被识别
if ([touch.view isKindOfClass:[YYLabel class]]) {
YYLabel *label = (YYLabel *)touch.view;
NSAttributedString *attributedString = label.attributedText;
NSUInteger index = attributedString.yy_rangeOfAll.location;
YYTextHighlight *hl = [attributedString yy_attribute:YYTextHighlightAttributeName atIndex:index]; //获取当前文本上是否有点击事件
isCanRecognize = hl ? NO : YES; //检查是否有有高亮对象
}
return isCanRecognize;
}
icoder20150719 commentedon Oct 9, 2018
@Liy666 你的这个方法不行 需要改动一下
(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
BOOL isCanRecognize = YES; //是否能被识别
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]; //获取当前文本上是否有点击事件
isCanRecognize = hl ? NO : YES; //检查是否有有高亮对象
}
return isCanRecognize;
}