【问题标题】:dismiss UINavigationController interactive关闭 UINavigationController 交互
【发布时间】:2015-01-12 00:46:07
【问题描述】:

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

我。我介绍如下:

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。有人对这可能是什么有任何建议吗?谢谢!

【问题讨论】:

  • 我不确定,但你可以试试[self.navigationController popViewControllerAnimated:YES]; 而不是[self dismissViewControllerAnimated:YES completion:nil];。我猜是这样。
  • 这很遗憾行不通

标签: ios uiviewcontroller uinavigationcontroller transitions


【解决方案1】:

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

当前呈现的 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 倍 - 任何关于为什么这可能会被赞赏的建议!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-01
    • 2017-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-18
    • 2012-08-01
    相关资源
    最近更新 更多