sender.view?.isHidden

I am currently working on a project which uses 3 UIImages and UITapGestureRecognizers, one for each image. I wanted to set up all three gesture recognizers to a single @IBAction, so when one image gets tapped, only that image is hidden. This is basically what I have:

@IBAction func handleTap(_ sender: UITapGestureRecognizer) {
        sender.view?.isHidden=true
    }

None of the images hide after I tap them, and I wasn't seeing anything online on how to fix it.
Any help would be greatly appreciated!

Replies

I tested in a project, that works.


How did you define the tapgestures exactly ?

In IB ?

In code ?


please detail, because the problem is likely there.

3 UITapGestureRecognizers and 3 UIImageViews all made in storyboard.
Now that I think about it, I don't think I specified userInteractionEnabled on the views.
Will check when I can.

Simple way to check (and always do when a func does not do what it should: test if it is called:


@IBAction func handleTap(_ sender: UITapGestureRecognizer) { 
       print(#function, "was called")
        sender.view?.isHidden=true 
    }

Okay, that was my bad. Forgot to enable user interaction. 😅

Thanks for feedback. Don't forget to close the thread.