swift Tap Gesture不会触发

时间:2017-02-07 15:30:05

标签: ios swift uipickerview uitapgesturerecognizer

每当我点击UIPickeView中的某个项目时,我想触发点按手势。

我使用以下代码进行LongPress Gesture工作正常。但是,如果我切换到UITapGestureRecognizer,则不会触发任何内容。

完整的代码更新!

 @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()
}

2 个答案:

答案 0 :(得分:0)

我相信评论中的@dfd是正确的。

示例:

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) {}

你确实错过了:

view.addGestureRecognizer(tapGesture)

更新:检查来自此SO的touchesBegan:touchesBegan Swift 3.0 有了它,您可以检查您的UIPicker是否正确地重新启动了触摸器。

答案 1 :(得分:0)

对于谁来点击手势不为他们工作,直到做出一切:

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

尝试符合UIGestureRecognizerDelegate然后 mKE tap.delegate = self,您必须实施此UIGestureRecognizerDelegate方法     使

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