Skip to content

YYlabel 事件和父视图手势冲突。 #38

@wy19901227

Description

@wy19901227

给YYlabel做了点击事件,父view上加了一个tap手势,然后YYlabel的事件就不执行了。希望可以解决下这个手势冲突。

Activity

hydyy

hydyy commented on Nov 27, 2015

@hydyy

确实 我也遇到了。

ibireme

ibireme commented on Nov 27, 2015

@ibireme
Owner

配置一下: gesture.cancelsTouchesInView = NO

wy19901227

wy19901227 commented on Nov 27, 2015

@wy19901227
Author

yes还是no 默认是yes

发自我的 iPhone

在 2015年11月27日,11:58,Yaoyuan notifications@github.com 写道:

配置一下: gesture.cancelsTouchesInView。


Reply to this email directly or view it on GitHub.

ibireme

ibireme commented on Nov 27, 2015

@ibireme
Owner

NO

LCcccccc

LCcccccc commented on Sep 11, 2016

@LCcccccc

@ibireme 我是在YYLabel上加了highlightTapAction,父view上加了一个tapGesture, cancelsTouchesInView设为NO后,再点击一下highlight文本时,会先触发父view的事件,再触发highlightTapAction,请问要怎样设置才能只触发highlightTapAction而不触发父view的事件呢?谢谢!

zhangyuhan18

zhangyuhan18 commented on Dec 11, 2017

@zhangyuhan18

@LCcccccc 你好,想请教一下这个问题解决了吗“父view上加了一个tapGesture, cancelsTouchesInView设为NO后,再点击一下highlight文本时,会先触发父view的事件,再触发highlightTapAction“

liycoding

liycoding commented on Aug 20, 2018

@liycoding

#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

icoder20150719 commented on Oct 9, 2018

@icoder20150719

@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;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ibireme@hydyy@liycoding@wy19901227@LCcccccc

        Issue actions

          YYlabel 事件和父视图手势冲突。 · Issue #38 · ibireme/YYText