Intercept tap event in given condition

I created a view with a UIPickerView which is showed when user push a button.

Now i need to make UIPickerView disappear when user tap anywhere on screen (obviously out of UiPickerView).

How can i intercept this tap only when UIPickerView is visible ? Thank you!

Answers


You may want to attach a UIGestureRecognizer to the main view. As soon as someone taps the main view somewhere, you can get an event and remove your UIPickerView. Write something like this in you ViewController:

UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] 
                         initWithTarget:self action:@selector(viewWasTapped)];
[self.view addGestureRecognizer:tgr];

In you viewWasTapped method you'll receive all Taps on the ViewControllers view.

Hope that helps.


Need Your Help

MVC Routing in Umbraco instance

c# asp.net-mvc-4 umbraco7

I wonder if someone could help me please....