我想双击。我写了函数doubleTap。如何识别手指的位置?

override func viewDidLoad()
{
    super.viewDidLoad()
    let doubleTap = UITapGestureRecognizer(target: self, action: "doubleTap")
    doubleTap.numberOfTapsRequired = 2
    doubleTap.numberOfTouchesRequired = 1
    view.addGestureRecognizer(doubleTap)
}
func doubleTap()
{

}

最佳答案

您可以将手势识别器作为参数

override func viewDidLoad()
{
    super.viewDidLoad()
    let doubleTap = UITapGestureRecognizer(target: self, action: #selector(doubleTapFunc))
    doubleTap.numberOfTapsRequired = 2
    doubleTap.numberOfTouchesRequired = 1
    view.addGestureRecognizer(doubleTap)
}

func doubleTapFunc(_ sender: UITapGestureRecognizer)
{
    // Use 'sender' here to get the location
    if sender.state == .ended {
        // handling code
        let location = sender.location(ofTouch: 0, in: self.view!)
    }
}

关于ios - 如何在功能中检测手指位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47622517/

10-12 04:44