Believe2014 Believe2014 - 4 months ago 11
iOS Question

How does the `tap` function get ignored?

Following Apple's Guide to build a MealKeeper app, I was able to create a text field and an image view. After dragging and dropping the

UITapGestureRecognizer
on top of the image view, I added the code to hide the keyboard by making the text field to resign.
MealKeeper

When I run this code in simulator, I first click on the text field, the keyboard appears.
Then I click on the image view, the keyboard does not get hide.

How does the
tap
function get ignored?

Answer

You need to add the gesture to you imageview, create an IBOutlet to your imageview and add the following to 'viewDidLoad'.

let tapGestureRecognizer = UITapGestureRecognizer(target:self, action:Selector("tap:"))
imageView.userInteractionEnabled = true
imageView.addGestureRecognizer(tapGestureRecognizer)

Good luck.