Ahmed Farag
Ahmed Farag

Reputation: 23

Gesture recognizer for UIImageView in UIView

I added UIImageView in superview then add required gestures and works fine but when doing the same in another UIView (add UIImageView in UIView and add gestures) it does not work I think it's about delegates but I can't figure it out.

Code in Swift please.

view hierarchy

Upvotes: 2

Views: 1669

Answers (1)

Lalit kumar
Lalit kumar

Reputation: 2207

Add UIGestureRecognizerDelegate

Ex-

self.imgView.isUserInteractionEnabled = true
self.view.isUserInteractionEnabled = true
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageTapped))
imgView.addGestureRecognizer(tapRecognizer)

Add Gesture you want on UIView or ImageView

func imageTapped(gestureRecognizer: UITapGestureRecognizer)
{
    let tappedImageView = gestureRecognizer.view!
    let imageView = tappedImageView as! UIImageView
 }

Upvotes: 5

Related Questions