In my app, to click a button will pop up a UIView, now I want to click anywhere outside of the UIView to dismiss the UIView.
I have tried adding a large transparent button under the UIView, invoke the button action to dismiss the UIView, but the button can't be expanded to Fullscreen because of the top navigationbar and bottom tabbar
Is any other way to achieve?
A giant UIButton
it's not very good solution to your problem. You can simple use a UIGestureRecognizer
for that.
You can allocate one like this:
UITapGestureRecognizer *tapImageRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissPopUp)];
Then, just add the gesture to the views you want to respond to the selector chosen.
[self.view addGestureRecognizer:tapImageRecognizer];
and possibly others
[self.navBar addGestureRecognizer:tapImageRecognizer];
//etc
Just don't forget to implement the method used by the gesture recognizer
-(void)dismissPopUp
{
//your dimiss code here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With