【问题标题】:Flip transition uinavigationcontroller push翻转过渡 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 的什么地方?

标签: ios objective-c uinavigationcontroller


【解决方案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)
            })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-01
      • 2014-02-21
      • 2010-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多