Touch event detection outside of a specific UIView

In my application, to click on the button, a UIView will appear, now I want to click somewhere outside of the UIView to reject the UIView.
I tried to add a large transparent button in the UIView, invoke the button action to reject the UIView, but the button cannot be expanded to full screen mode due to the top navigation bar and bottom panel Is there any other way to achieve?

+4
source share
1 answer

Giant UIButton is not a good solution to your problem. You can simply use UIGestureRecognizer for this.

You can highlight the following:

 UITapGestureRecognizer *tapImageRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissPopUp)]; 

Then just add a gesture to the views you want to respond to the selected selector.

 [self.view addGestureRecognizer:tapImageRecognizer]; 

and possibly others

 [self.navBar addGestureRecognizer:tapImageRecognizer]; //etc 

Just remember to implement the method used by the gesture recognizer

 -(void)dismissPopUp { //your dimiss code here } 
+8
source

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


All Articles