Reputation: 23
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.
Upvotes: 2
Views: 1669
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