zoukankan      html  css  js  c++  java
  • YYlabel 事件和父视图手势冲突,highlightTapAction无反应

    父视图手势设置

     forwardView.isUserInteractionEnabled = true
     let tap = UITapGestureRecognizer(target: self, action: #selector(forwardViewTapClick))
     tap.cancelsTouchesInView = false
     tap.delaysTouchesBegan = false
     tap.delegate = self
     self.forwardView.addGestureRecognizer(tap)

    子视图YYLabel的highlightTapAction

    forwardContentLabel.highlightTapAction = {[weak self] (containerView, text, range, rect) in
                if let strongSelf = self {
                    let attribute = strongSelf.forwardContentLabel.textLayout?.text
                    let highlight = attribute?.attribute(YYTextHighlightAttributeName, at: UInt(range.location)) as? YYTextHighlight
                    
                    guard let userInfo = highlight?.userInfo as? [String: Any] else { return }
                  
                }
            }
            self.forwardView.addSubview(forwardContentLabel)

    实现手势代理

    extension PostView: UIGestureRecognizerDelegate{
        
        func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
            var isCanRecognize = true   //是否能被识别
            
            if ((touch.view as? YYLabel) != nil) {
                let label = touch.view as! YYLabel
                let attributedString = label.textLayout?.text
                let index : NSInteger? = label.textLayout?.textRange(at: touch.location(in: label))?.start.offset
                if index != nil, index! > 0 {
                    let highlight = attributedString?.attribute(YYTextHighlightAttributeName, at: UInt(index!))
                    isCanRecognize = highlight != nil ? false : true
                }
            }
            return isCanRecognize
        }
    
    }
  • 相关阅读:
    linux 下安装mongodb
    python 多线程, 多进程, 协程
    5.rabbitmq 主题
    4.rabbitmq 路由
    e.target与e.currentTarget对比
    使用ffmpeg下载m3u8流媒体
    本机添加多个git仓库账号
    IE hack 条件语句
    IE8 兼容 getElementsByClassName
    IE 下 log 调试的一点不同
  • 原文地址:https://www.cnblogs.com/leqoqo/p/14980389.html
Copyright © 2011-2022 走看看