gpt4 book ai didi

ios - 将 UITapGestureRecognizer 添加到 UITextView 而不阻止 textView 触摸

转载 作者:IT王子 更新时间:2023-10-29 05:29:17 26 4
gpt4 key购买 nike

我怎样才能将 UITapGestureRecognizer 添加到 UITextView,但仍能像正常一样将触摸传递到 UITextView

目前,只要我向我的 textView 添加自定义手势,它就会阻止 UITextView 默认操作(例如定位光标)的点击。

var tapTerm:UITapGestureRecognizer = UITapGestureRecognizer()

override func viewDidLoad() {
tapTerm = UITapGestureRecognizer(target: self, action: "tapTextView:")
textView.addGestureRecognizer(tapTerm)
}

func tapTextView(sender:UITapGestureRecognizer) {
println("tapped term – but blocking the tap for textView :-/")

}

我如何处理点击,但保持任何 textView 行为(如光标定位)不变?

最佳答案

要做到这一点,让您的 View Controller 采用 UIGestureRecognizerDelegate 并覆盖应该同时识别手势识别器方法,例如:

override func viewDidLoad() {
tapTerm = UITapGestureRecognizer(target: self, action: "tapTextView:")
tapTerm.delegate = self
textView.addGestureRecognizer(tapTerm)
}

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {

return true
}

关于ios - 将 UITapGestureRecognizer 添加到 UITextView 而不阻止 textView 触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28858908/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com