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
        }
    
    }
  • 相关阅读:
    Fixed Function Shader
    sqlserver 2014 数据库作业 通过脚本创建注意事项
    块存储、文件存储、对象存储意义及差异
    程序员如何成为架构师
    那些编程水平很高的程序员是怎么练成的?
    在ASP.NET Core调用WebService
    .net core 调用webservice同步方法
    Sqlserver中如何创建链接服务器
    JWT实现鉴权
    JWT原理实现代码
  • 原文地址:https://www.cnblogs.com/leqoqo/p/14980389.html
Copyright © 2011-2022 走看看