Swift3 UITapGestureRecognitor错误

Swift3 UITapGestureRecognitor错误,swift3,uitapgesturerecognizer,Swift3,Uitapgesturerecognizer,我为这个问题挣扎了几个小时。我似乎无法理解使用UITapGestureRecognitor的过程。任何帮助都将不胜感激 @IBOutlet weak var textView: UITextView! override func viewDidLoad() { let textInView = "This is my text." textView.text = textInView let tapGesture = UITapGestureRecognizer(ta

我为这个问题挣扎了几个小时。我似乎无法理解使用UITapGestureRecognitor的过程。任何帮助都将不胜感激

@IBOutlet weak var textView: UITextView!

override func viewDidLoad() {
    let textInView = "This is my text."
    textView.text = textInView

    let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapResponse(_:)))
    tapGesture.numberOfTapsRequired = 1
    textView.addGestureRecognizer(tapGesture)

    func tapResponse(sender: UITapGestureRecognizer) {
        var location: CGPoint = sender.location(in: textView)
        location.x = textView.textContainerInset.left
        location.y = textView.textContainerInset.top

        print(location.x)
        print(location.y)
    }
 }
在函数(
viewDidLoad
)中有一个函数(
tapResponse

将其置于
viewDidLoad
之外。然后像这样引用它:

override func viewDidLoad() {
    super.viewDidLoad() // Remember to always call super.

    let tapGesture = UITapGestureRecognizer(
        target: self,
        action: #selector(ViewController.tapResponse(sender:)) // Referencing.
    )

    tapGesture.numberOfTapsRequired = 1
    textView.addGestureRecognizer(tapGesture)
}

// tapResponse is now outside of viewDidLoad:
func tapResponse(sender: UITapGestureRecognizer) {
    var location: CGPoint = sender.location(in: imageView)
    location.x = textView.textContainerInset.left
    location.y = textView.textContainerInset.top    
    print(location.x)
    print(location.y)
}
完成:

在函数(
viewDidLoad
)中有一个函数(
tapsresponse

将其置于
viewDidLoad
之外。然后像这样引用它:

override func viewDidLoad() {
    super.viewDidLoad() // Remember to always call super.

    let tapGesture = UITapGestureRecognizer(
        target: self,
        action: #selector(ViewController.tapResponse(sender:)) // Referencing.
    )

    tapGesture.numberOfTapsRequired = 1
    textView.addGestureRecognizer(tapGesture)
}

// tapResponse is now outside of viewDidLoad:
func tapResponse(sender: UITapGestureRecognizer) {
    var location: CGPoint = sender.location(in: imageView)
    location.x = textView.textContainerInset.left
    location.y = textView.textContainerInset.top    
    print(location.x)
    print(location.y)
}
完成:


谢谢!这已经困扰我很长时间了。谢谢!这困扰了我很长时间。