关闭 UINavigationController 交互

dismiss UINavigationController interactive

我正在尝试以交互方式关闭 UINavigationController,它的堆栈上有 UIViewController

我。我介绍如下:

UIViewController *vc = [UIViewController new];
UINavigationController *nav = [[UINavigationController alloc] initWithRoot:vc];
[self presentViewController:nav animated:YES completion:nil];

ii.. 在我的 ViewController 中,我已经在 .h 文件中进行了设置。在我设置的.m文件中 self.transitioningDelegate.self 我也试过 self.navigationController.transitioningDelegate = self

三。最后我实现了委托方法:

#pragma mark - ViewControllerTransitioning Delegate Methods
- (id<UIViewControllerAnimatedTransitioning>)
animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source {
    NSLog(@"\n\nTRANSIT 1\n\n");
    // allow the interaction controller to wire-up its gesture recognisers
    [_interactionController wireToViewController:presented
                                    forOperation:CEInteractionOperationDismiss];
    _animationController.reverse = NO;
    return _animationController;
}

- (id<UIViewControllerAnimatedTransitioning>)
animationControllerForDismissedController:(UIViewController *)dismissed {
    NSLog(@"\n\nTRANSIT 2\n\n");
    _animationController.reverse = YES;
    return _animationController;
}

- (id<UIViewControllerInteractiveTransitioning>)
interactionControllerForDismissal:
(id<UIViewControllerAnimatedTransitioning>)animator {
    NSLog(@"\n\nTRANSIT 3\n\n");
    // provide the interaction controller, if an interactive transition is in progress
    return _interactionController.interactionInProgress
    ? _interactionController : nil;
}

四。不幸的是,交互部分永远不会执行。当我手动点击一个调用 [self dismissViewControllerAnimated:YES completion:nil];

的按钮时

Transit 2 和Transit 3 都被打印出来了,但是Transit 1 从来没有到达过。有人有什么建议吗?谢谢!

是的!终于解决了这个问题。问题是,在使用 UINavigationController *n = [[UINavigationController alloc] initWithRoot:yourVC] [self presentViewController:n animated:YES completion:nil];

呈现新的 UIViewController

当前呈现 ViewController 将在 n 中查找 transitioningDelegate 方法,特别是:

- (id<UIViewControllerAnimatedTransitioning>)
animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source {
    NSLog(@"\n\nTRANSIT 1\n\n");
    // allow the interaction controller to wire-up its gesture recognisers
    [_interactionController wireToViewController:presented
                                    forOperation:CEInteractionOperationDismiss];
    _animationController.reverse = NO;
    return _animationController;
}

未调用用于连接 interactionController 的手势识别器的。因此,为了避免这个问题,我们必须在 ViewController 的要呈现的 viewDidLoad 中调用以下内容:

[_interactionController wireToViewController:self forOperation:CEInteractionOperationDismiss];

这样 viewController 就可以连接起来了。唯一突出的问题是,视图中的翻译似乎增加了 5 倍 - 任何关于为什么会这样的建议都值得赞赏!