类型'CameraViewController'没有成员'handleTap'

时间:2018-06-12 01:24:26

标签: ios swift

我有一个视图控制器:

class CameraViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    ...
    override func viewDidLoad() {
        super.viewDidLoad()
        self.recordingSpinner.isUserInteractionEnabled = true
        let tap = UITapGestureRecognizer(target: self, action: #selector(CameraViewController.handleTap(_:)))
        self.recordingSpinner.addGestureRecognizer(tap)
        if setupSession(){
            setupPreview()
            startSession()
        }
    }

    @objc func handleTap(gesture:UIGestureRecognizer) {
        startRecording()
        guard let animator = animator else {
            createAnimation()
            return
        }

        if animator.isRunning {
            animator.pauseAnimation()
        } else {
            animator.startAnimation()
        }
    }
}

XCode抱怨它在CameraViewController中找不到handleTap但我看到了。我需要改变什么?

1 个答案:

答案 0 :(得分:0)

正如@dan建议的那样,执行@objc func handleTap(_ gesture: UIGestureRecognizer)代替@objc func handleTap(gesture:UIGestureRecognizer)修复它。

还使用let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap)  也适用