4

我正在使用 aUIPresentationController来显示自定义模式。演示控制器在显示UIView时有一个调光视图。模态本身是UIViewController添加到演示控制器的容器中的。

问题

我只能[self dismissViewControllerAnimated:NO completion:nil]从嵌入式 UIViewController 调用。但我不能从UIPresentationController. 但这就是变暗视图的所在。

我想避免向模态添加额外的不可见视图,或者NSNotificationCenter尽可能使用。

你如何UIPresentationController通过点击它的调光视图来关闭它?是否有意义?可能吗?

4

3 回答 3

6

好的,我找到了。您可以通过以下方式到达显示的 UIViewController 以关闭self.presentedViewController

[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
于 2015-12-17T02:57:42.793 回答
2

你可以试试这个:

- (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];
}
于 2015-12-16T16:00:17.317 回答
0

是的,这是可能的......首先你必须在调光视图上添加点击手势并添加点击手势动作......

[self dismissViewControllerAnimated:YES completion:nil];

这将解决您的问题。

于 2018-02-23T10:52:22.090 回答