简体   繁体   English

快速点击手势不触发

[英]swift Tap Gesture not triggering

I want to trigger the tap gesture whenever I tap on an item in my UIPickeView. 我想在我的UIPickeView中的某个项目上点击时触发点击手势。

I'm using the following code for LongPress Gesture which works fine. 我对LongPress Gesture使用以下代码,效果很好。 However if I switch to UITapGestureRecognizer, nothing is triggered. 但是,如果我切换到UITapGestureRecognizer,则不会触发任何操作。

FULL CODE UPDATE! 完整代码更新!

 @IBOutlet weak var showClaims: UIPickerView!

    override func viewDidLoad() {

        super.viewDidLoad()
showClaims.isUserInteractionEnabled = true
        let tapped = UITapGestureRecognizer(target: self, action: #selector(ClaimVC.SelectClaimInfo))

        showClaims.addGestureRecognizer(tapped)
}


func SelectClaimInfo() {
        GetClaimInfo()
}

I believe @dfd is correct in the comments. 我相信@dfd在评论中是正确的。

Example: 例:

override func viewDidLoad()
{
    super.viewDidLoad()
    setupTapGesture()
}

private func setupTapGesture()
{
    let tapGesture = UITapGestureRecognizer(target: self,
                                            action: #selector(myVC.doStuff(_:)))
    view.addGestureRecognizer(tapGesture)
}

func doStuff(gesture: UITapGestureRecognizer) {}

You did miss the: 您确实错过了:

view.addGestureRecognizer(tapGesture)

Update: check touchesBegan from this SO: touchesBegan Swift 3.0 With it you can check if your UIPicker is reaciving touchers properly. 更新:检查touchesBe从此开始: touchesBegan Swift 3.0有了它,您可以检查UIPicker是否正确地抚摸触摸屏。

For who Tap Gesture not work for them until make everything as that: 对于谁打手势,谁不为他们工作,直到一切成为那样:

let tap = UITapGestureRecognizer(target: self, action:#selector(self.handleTap(_:)))
myView.addGestureRecognizer(tap)

try to conforms UIGestureRecognizerDelegate and then mKE tap.delegate = self and you must implement this UIGestureRecognizerDelegate method make 尝试符合UIGestureRecognizerDelegate ,然后符合mKE tap.delegate = self ,则必须实现此UIGestureRecognizerDelegate方法

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return true
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM