Closed vietnguyen09 closed 8 years ago
@vietnguyen09 think you are referring self.popupController in a wrong view controller. backgroundViewDidTap should be called in your POPViewController.
It's error
backgroundViewDidTap]: unrecognized selector sent to instance 0x15780b7b0
Main.m
[popupController.backgroundView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundViewDidTap)]];
Pop.h
- (IBAction)backgroundViewDidTap;
Pop.m
- (IBAction)backgroundViewDidTap
{
// [self.popupController dismiss];
NSLog(@"Tapping in background2.");
}
The target is not "self" in this case. Please read more about how to use gesture recognizer.
I've just copied your example in readme, I've searched in your example project but its not contains any example about dismiss popup by tapping background.
- (void)showPopupDaudit{
STPopupController *popupController = [[STPopupController alloc] initWithRootViewController:[POPViewController new]];
[STPopupNavigationBar appearance].tintColor = MP_HEX_RGB(MAINCOLOR);;
popupController.containerView.layer.cornerRadius = 4;
if (NSClassFromString(@"UIBlurEffect")) {
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
popupController.backgroundView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
}
[popupController.backgroundView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:popupController
action:@selector(backgroundViewDidTap)]];
[popupController presentInViewController:self];
}
Still error.
Please help
@vietnguyen09 You should set the POPViewController
as target, not the STPopupController
.
Main.m:
POPViewController *vc = [[POPViewController alloc] init];
STPopupController *popupController = [[STPopupController alloc] initWithRootViewController:vc];
[popupController.backgroundView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:vc action:@selector(backgroundViewDidTap)]];
POPViewController.h:
-(void)backgroundViewDidTap;
POPViewController.m:
- (void)backgroundViewDidTap
{
[self.popupController dismiss];
}
In iOS 11 this solution will not work. Here is the suggestion:
[[(UIVisualEffectView *)popupController.backgroundView contentView] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:vc action:@selector(backgroundViewDidTap)]];
I've done like readme but it's not working, it's a bug? NSlog trigger show fine but popup never close.