I am stuck in adding tap gesture recogniser for UIImageView in a UIView. I did put the isUserInteractionEnabled = true for both UIImageView And UIView. but it still not working.
@IBOutlet weak var adView: UIView!<br>
@IBOutlet weak var defaultBannerView: UIImageView!
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(FavouritesVC.tappedImageBanner(_:)))
defaultBannerView.addGestureRecognizer(tapGesture) defaultBannerView.isUserInteractionEnabled = true adView.isUserInteractionEnabled = true
func tappedImageBanner(_ sender: UIGestureRecognizer){
print("Tapped")
let tappedImageView = sender.view!
let imageView = tappedImageView as! UIImageView
print(imageView) }
Edit:
I added adView.addGestureRecognizer(tapGesture) but the error is 'Could not cast value of type 'UIView' to 'UIImageView''
Actually I am doing admob, I want to put my default Banner when I can't request the banner from google admob. So I want user to able to click on my default banner and direct to the website. So should I just add the tapGesture in the adView and hide the imageView when I can get the ad from google?
what if I want to add gesture in UIImageView? how should I do that?