我想在两个导航控制器之间进行自定义转换。我们将第一个称为sourceController,将另一个称为detailNavController

这是我的代码:

NewEntryViewController *viewController = [[NewEntryViewController alloc]
                                                                  initWithStyle:UITableViewStyleGrouped];
viewController.parentController = self;

UINavigationController *detailNavController = [[UINavigationController alloc]
                                                                  initWithRootViewController:viewController];

[UIView beginAnimations:nil context:NULL];
[self.navigationController presentModalViewController:detailNavController animated:NO];

[UIView setAnimationDuration:0.4];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:sourceController.view cache:YES];

[UIView commitAnimations];


SourceController首先以模态呈现,这就是为什么我以模态呈现detailNavController的原因。这段代码的问题是动画发生了,但是sourceController仍然在新的detailNavController之上。我想要实现的是制作动画,然后关闭sourceController并显示detailNavController

最佳答案

我终于找到了解决方案,这是更新的代码:

- (void)createNewEntryWithAnimation
{
    // before calling this method I dismissed sourceController without animation
    NewEntryViewController *viewController = [[NewEntryViewController alloc] initWithStyle:UITableViewStyleGrouped];
    viewController.parentController = self;

    UINavigationController *detailNavController = [[UINavigationController alloc]
                                                   initWithRootViewController:viewController];

    [UIView beginAnimations:nil context:NULL];
    [self.navigationController presentModalViewController:detailNavController animated:NO];

    [UIView setAnimationDuration:0.4];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:viewController.view.window cache:NO];

    [UIView commitAnimations];
}


我必须使用cache:NO,否则过渡不顺利。

关于iphone - 导航 Controller 之间的自定义过渡,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5286278/

10-09 09:37