Capture a transition event in a given state

I created a view with a UIPickerView that displays when the user clicks a button.

Now I need to make the UIPickerView disappear when the user clicks anywhere on the screen (obviously from the UiPickerView).

How can I intercept this retraction only when a UIPickerView is displayed? Thank!

+3
source share
1 answer

You might want to attach the UIGestureRecognizer to the main view. Once someone closes the main view, you can receive the event and delete your UIPickerView. Write something like this in ViewController:

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

In your viewWasTapped method, you get all the taps in the ViewControllers view.

, .

+2

Source: https://habr.com/ru/post/1778490/


All Articles