【问题标题】:Push ViewController with modal animation (horizontal flip)使用模态动画推送 ViewController(水平翻转)
【发布时间】:2013-02-10 11:48:21
【问题描述】:

我需要将一个视图控制器推送到另一个视图控制器。

menuVC -> VC1 ->VC2

从 menuVC 到 VC1 不需要动画,但是从 VC1 到 VC2 和从 VC2 到 VC1 需要发生翻转动画。

但是,当从 VC2 转到 menuVC 时,不需要动画。

我正在使用以下代码:

(来自how to push a viewController with flip animation

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
FlashCardVC *flashCardVC = [[FlashCardVC alloc] init];
[self.navigationController pushViewController:flashCardVC animated:NO];
[UIView commitAnimations];

当我尝试执行上述操作时,屏幕完全空白。

怎么了?

【问题讨论】:

    标签: iphone ios objective-c uiviewcontroller modalviewcontroller


    【解决方案1】:

    你现在真的应该使用基于块的动画。此外,如果您从同样位于同一故事板中的控制器实例化故事板控制器,您可以使用 self.storyboard 更轻松地访问该故事板。

    -(IBAction)flipToNext:(id)sender {
        SecondController *next = [self.storyboard instantiateViewControllerWithIdentifier:@"Next"];
        [self.navigationController pushViewController:next animated:NO];
        [UIView transitionWithView:self.navigationController.view duration:1 options:UIViewAnimationOptionTransitionFlipFromRight animations:nil completion:nil];
    }
    

    【讨论】:

    • 知道如何为 iOS 8 样式转换更新此答案吗?
    • @hsavit1,你在问什么 iOS 8 风格的过渡?
    【解决方案2】:

    在 Swift 4.2 中使用这些扩展

    用于带有水平翻转动画的推送和弹出视图控制器

    extension UINavigationController {
    
        func pushViewControllerWithFlipAnimation(viewController:UIViewController){
            self.pushViewController(viewController
            , animated: false)
            if let transitionView = self.view{
                UIView.transition(with:transitionView, duration: 0.8, options: .transitionFlipFromLeft, animations: nil, completion: nil)
            }
        }
    
        func popViewControllerWithFlipAnimation(){
            self.popViewController(animated: false)
            if let transitionView = self.view{
                UIView.transition(with:transitionView, duration: 0.8, options: .transitionFlipFromRight, animations: nil, completion: nil)
            }
        }
    }
    

    【讨论】:

      【解决方案3】:

      很好的答案: Showing pushviewcontroller animation look like presentModalViewController

      (代码)

          //UIViewController *yourViewController = [[UIViewController alloc]init];</s>
      
          [UIView  beginAnimations: @"Showinfo"context: nil];
          [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
          [UIView setAnimationDuration:0.75];
          [self.navigationController pushViewController: yourViewController animated:NO];
          [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
          [UIView commitAnimations];
      

      但是,这也产生了一个空白屏幕。

      相反,如果您使用情节提要,最好通过情节提要进行实例化:

      UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle bundleForClass:[self class]]];
      
      YourViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:@"yourViewControllerID"];
      

      yourViewControllerID 在情节提要中设置在 yourviewcontroller 类的身份检查器下。

      【讨论】:

      • 请将此答案标记为已接受,以便此问题不会出现在未回答的问题列表中。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-17
      • 2019-09-04
      • 1970-01-01
      相关资源
      最近更新 更多