如何将手势识别器添加到嵌套在UIView上的RichTextView中?

时间:2019-07-19 05:04:00

标签: swift xcode cocoapods

我想将手势识别器添加到Rich Text View中,它基本上是一个UIView,具有更多功能,这些功能我已将其添加到名为“ superiorView”的普通UIView中,我从Cocoa Pods下载了该软件包:

https://cocoapods.org/pods/RichTextView

我尝试了以下代码,但是没有用:


override func viewDidLoad(){

     super.viewDidLoad()


    let richTextView = RichTextView(
                        input: "hello",
                        latexParser: LatexParser(),
                        font: UIFont.systemFont(ofSize: UIFont.systemFontSize + 2),
                        textColor: UIColor.white,
                        isSelectable: false,
                        isEditable: false,
                        frame: CGRect(x: 0, y: 0, width: superiorView.frame.width, height: superiorView.frame.height),
                        completion: nil
                    )


    richTextView.isUserInteractionEnabled = true

            let tapgesture = UITapGestureRecognizer(target: self, action: #selector(self.clickLabel_1(_:)))
        tapgesture.numberOfTapsRequired = 1


            richTextView.addGestureRecognizer(tapgesture)


           superiorView.addSubview(richTextView)

}



@objc func clickLabel_1(_ sender:UIGestureRecognizer ){
        print("CLICKKKK 1 !")
    }

1 个答案:

答案 0 :(得分:0)

您正在配置手势识别器,但是您没有在代码中将其添加到richTextView中:

    richTextView.addGestureRecognizer(tapgesture) // add gesture recognizer to text view.