PruitIgoe
PruitIgoe

Reputation: 6384

Swift 3 TapGestureRecognizer selector throwing error

I've looked at a couple of other post with issues of adding a target to not just tap gestures and buttons and I think I am following the formatting correctly but am still getting the 'has no member' error, here's my pseudo code:

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.handlTap(_:)))

func handleTap(_ sender: AnyObject) {
    }

Upvotes: 0

Views: 155

Answers (2)

Nishant Bhindi
Nishant Bhindi

Reputation: 2252

To access any object with UITapGestureRecognizer

  let recognizer = UITapGestureRecognizer(target: self, action: #selector(self.expand))
  view.addGestureRecognizer(recognizer)
  func expand(sender:UITapGestureRecognizer){
   if let myImg = sender.view as? UIImageView //or AnyObject you want {

}
  }

Upvotes: 1

Abdoelrhman
Abdoelrhman

Reputation: 916

add the gesture to your view:

view.addGestureRecognizer(yourGesture)

Upvotes: 1

Related Questions