我想将手势识别器添加到富 TextView 中,该 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 !")
}
最佳答案
您正在配置手势识别器,但代码中没有将其添加到 richTextView:
richTextView.addGestureRecognizer(tapgesture) // add gesture recognizer to text view.
关于swift - 如何向嵌套在 UIView 上的 RichTextView 添加手势识别器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57105818/