How to change the Push and Pop animations in a navigation based app

前端 未结 25 1457
清酒与你
清酒与你 2020-11-22 12:46

I have a navigation based application and I want to change the animation of the push and pop animations. How would I do that?

Edit 2018

Ther

25条回答
  •  庸人自扰
    2020-11-22 13:21

    While all the answers here are great and most work very well, there is a slightly simpler method which achieves the same effect...

    For Push:

      NextViewController *nextViewController = [[NextViewController alloc] init];
    
      // Shift the view to take the status bar into account 
      CGRect frame = nextViewController.view.frame;
      frame.origin.y -= 20;
      frame.size.height += 20;
      nextViewController.view.frame = frame;
    
      [UIView transitionFromView:self.navigationController.topViewController.view toView:nextViewController.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
        [self.navigationController pushViewController:nextViewController animated:NO];
      }];
    

    For Pop:

      int numViewControllers = self.navigationController.viewControllers.count;
      UIView *nextView = [[self.navigationController.viewControllers objectAtIndex:numViewControllers - 2] view];
    
      [UIView transitionFromView:self.navigationController.topViewController.view toView:nextView duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
        [self.navigationController popViewControllerAnimated:NO];
      }];}
    

提交回复
热议问题