I have a UIImage that contains a mask of another UIImage. The only problem is when I tap the area outside the mask, the script still thinks I'm tapping the image.
let tap = UITapGestureRecognizer() override func viewDidLoad() { super.viewDidLoad() tap = UITapGestureRecognizer(target: self, action: #selector(ViewController.handleTap(_:))) tap.numberOfTapsRequired = 1 tap.numberOfTouchesRequired = 1 let imageMask = UIImageView() imageMask.image = ...//Image to mask to imageMask.frame = imageView.bounds imageView = UIImageView(image: ...) imageView.mask = imageMask imageView.addGestureRecognizer(tap) } @objc func handleTap(_ sender: UITapGestureRecognizer) { print("hello") //prints "hello" when tapped Image outside of mask } How to I completely crop the image to the mask, so It won't register taps outside of the mask?