翻转过渡 uinavigationcontroller push

Posted

技术标签:

【中文标题】翻转过渡 uinavigationcontroller push【英文标题】:Flip transition uinavigationcontroller push 【发布时间】:2013-09-24 13:16:28 【问题描述】:

我正在使用以下代码将 UIViewController 推送到导航堆栈中

[UIView animateWithDuration:0.75
                     animations:^
                         [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                         [self.navigationController pushViewController:ViewController animated:NO];
                         [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
                     ];

现在,当我按下返回时,我希望它执行相同的动画,但它不起作用。知道为什么吗?

在 ViewController.m 中

[UIView animateWithDuration:0.75
                     animations:^
                         [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                         [self.navigationController popToRootViewControllerAnimated:NO];
                         [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
                     ];

【问题讨论】:

你把代码放在 ViewController.m 的什么地方? 【参考方案1】:

其实过渡应该是这样的

//主视图

[UIView transitionWithView:self.navigationController.view
                      duration:0.75
                       options:UIViewAnimationOptionTransitionFlipFromRight
                    animations:^
                        [self.navigationController pushViewController:viewcontroller animated:NO];
                    
                    completion:nil];

//在视图控制器中

[UIView transitionWithView:self.navigationController.view
                  duration:0.75
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                animations:^
                    [self.navigationController popToRootViewControllerAnimated:NO];
                
                completion:nil];

【讨论】:

你能告诉我为什么 self.view 不工作而不是 self.navigationController.view @SuryaKantSharma 一般的想法是 NavigationController 拥有一个 viewController 数组。在视图级别内部,navigationController.view 将持有 viewcontroller.view,并且 push/pop 转换在 navigationController.view 上完成。所以 navigationController.view 应该是过渡视图。【参考方案2】:
//FirstViewController
[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationDuration:0.8]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController: viewcontroller
 animated:NO];
[UIView commitAnimations];

//SecondViewController
[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationDuration:0.8];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];

【讨论】:

【参考方案3】:

在 Swift 4 中:

推送:

UIView.transition(with: (self.navigationController?.view)!, duration: 0.75, options: .transitionFlipFromRight, animations: 
            self.navigationController?.popViewController(animated: true)
        )

流行:

  UIView.transition(with: (self.navigationController?.view)!, duration: 0.75, options: .transitionFlipFromLeft, animations: 
            self.navigationController?.popViewController(animated: true)
        )

【讨论】:

以上是关于翻转过渡 uinavigationcontroller push的主要内容,如果未能解决你的问题,请参考以下文章

更改 UINavigationController 过渡效果的正确方法是啥

UINavigationController 自定义模态过渡,导航栏太小

UINavigationController 自定义过渡移除下面的视图

在 UISplitViewController 中弹出 UINavigationController 会导致奇怪的过渡

UINavigationController 上视图之间的过渡动​​画有多长?

UINavigationController 过渡动画触发太快