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

How can I make a second fork of a GitHub project?

github

I want to fork a github project to fix a couple of issues and then send a pull request.

How to clone div with html controls without their content using jquery & refresh dropdown for IE?

javascript asp.net-mvc-3 jquery-ui jquery

I am using jquery .clone() function to clone a div which is having 6 controls (dropdowns, textboxes etc) .I have a functionality where there are 2 dropdowns DDL A & DDL B . Now changing the DDL A

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.