我正在使用一个UIPresentationController来显示一个自定义模式。显示时,演示控制器具有在out中以动画形式显示的UIView调光视图。模态本身就是一个添加到表示控制器容器中的UIViewController。
问题所在
我只能从嵌入式UIViewController调用[self dismissViewControllerAnimated:NO completion:nil]。但是我不能在UIPresentationController上做同样的事情。但这就是调光视线所在。
如果可能的话,我希望避免向模型中添加额外的不可见视图,或者使用NSNotificationCenter。
你如何通过点击UIPresentationController的调光视图来关闭它?这有意义吗?有可能吗?
发布于 2015-12-17 10:57:43
好吧,我找到了。您可以通过self.presentedViewController访问所示的UIViewController进行解除
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];发布于 2015-12-17 00:00:17
您可以尝试这样做:
- (void)viewDidAppear:(BOOL)animated {
if (!self.tapOutsideRecognizer) {
UITapGestureRecognizer *tapOutsideRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapBehind:)];
self.tapOutsideRecognizer.numberOfTapsRequired = 1;
self.tapOutsideRecognizer.cancelsTouchesInView = NO;
self.tapOutsideRecognizer.delegate = self;
[self.view.window addGestureRecognizer:self.tapOutsideRecognizer];
}
}
- (void)handleTapBehind:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
CGPoint location = [sender locationInView:nil];
if (![self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil]) {
[self.view.window removeGestureRecognizer:sender];
[self back:sender];
}
}
}
- (IBAction)back:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}发布于 2018-02-23 18:52:22
这是可能的..。首先,你必须在调光视图中添加轻拍手势,并添加轻拍手势动作...
[self dismissViewControllerAnimated:YES completion:nil];这将解决您的问题。
https://stackoverflow.com/questions/34308425
复制相似问题