解雇UINavigationController交互式

时间:2015-01-12 00:46:08

标签: ios uiviewcontroller uinavigationcontroller transitions

我正在尝试以交互方式解除其堆栈上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

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

#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;
}

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

的按钮时

Transit 2和Transit 3都已打印,但从未到达Transit 1。有人有什么建议吗?谢谢!

1 个答案:

答案 0 :(得分:0)

是的!终于解决了这个。问题是,在使用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倍 - 任何关于为什么会这样做的建议都会受到赞赏!