在Swift 4和iOS 11中快速点击手势

时间:2018-01-18 21:42:26

标签: ios swift ios11 swift4 gestures

我只是制作了一个简单的应用来尝试任何类型的手势。我做了轻拍手势。所以我想,如果我做了一个快速的点击游戏类型的应用程序,计算用户执行的点击量。但很快我遇到了一些问题。

它没有计算所有的水龙头。如果我开始尽可能快地点击,但它跳过了水龙头。

我的想法是以编程方式在superview中创建了一个视图,并在视图上添加了tapGestureRecognizer。只需将“点击”放入应用程序中的标签即可。

似乎无法按时收到系统手势。

代码:

let tap = UITapGestureRecognizer(target: self, action: #selector(tapped(sender:)));
    tap.numberOfTapsRequired = 1;
    animationView.isUserInteractionEnabled = true;
    animationView.addGestureRecognizer(tap);

功能:

@objc func tapped (sender :UITapGestureRecognizer) {
   self.counter += 1;
   self.lblScore.text = String(self.counter);
}

我有一个动画视图,我做了“tappable”,它的工作原理。每次点击animationView时,它都会增加“计数器”的值!但如果我点击太快,每次出现此错误时都会:

<_UISystemGestureGateGestureRecognizer: 0x1c01c4b00>: Gesture: Failed to receive system gesture state notification before next touch

1 个答案:

答案 0 :(得分:0)

  

制作手势:

let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))
panGesture.delegate = self
Button.addGestureRecognizer(panGesture)

let longTapGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongTapGesture(_:)))
Button.addGestureRecognizer(longTapGesture)

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:)))
Button.addGestureRecognizer(tapGesture)

let rotateGesture = UIRotationGestureRecognizer(target: self, action: #selector(handleRotateGesture(_:)))
rotateGesture.delegate = self
Button.addGestureRecognizer(rotateGesture)

let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(handlePinchGesture(_:)))
pinchGesture.delegate = self
Button.addGestureRecognizer(pinchGesture)    
  

手势点击活动

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

    @IBAction func handlePanGesture(_ recognizer: UIPanGestureRecognizer) {

    }

    @IBAction func handlePinchGesture(_ recognizer: UIPinchGestureRecognizer) {

    }

    @IBAction func handleRotateGesture(_ recognizer: UIRotationGestureRecognizer) 
    {

    }

    @IBAction func handleTapGesture(_ recognizer: UITapGestureRecognizer) {

    }

    @IBAction func handleLongTapGesture(_ recognizer: UITapGestureRecognizer) {

    }
}