Flip animation when controller pushed on iPhone

前端 未结 4 739
失恋的感觉
失恋的感觉 2020-12-23 23:36

I had a look around and didn\'t find what I was exactly looking for.

Is there a way to get a flip animation when pushing a view controller?

I read that you c

相关标签:
4条回答
  • 2020-12-24 00:12

    For modally presented view controllers, you can change the animation with the modalTransitionStyle property. AFAIK, there is no way to change a navigation controller's push animation (except rebuilding UINavigationController from scratch).

    0 讨论(0)
  • 2020-12-24 00:16

    something like this should work

    [UIView beginAnimations:@"animation" context:nil];
    [self.navigationController pushViewController: yourviewcontroller animated:NO]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
    [UIView commitAnimations];
    

    don't forget to set animated to NO when calling pushViewController

    0 讨论(0)
  • 2020-12-24 00:21

    This also works.. for iOS 4.0 and greater

    [UIView  transitionWithView:self.navigationController.view duration:0.8  options:UIViewAnimationOptionTransitionFlipFromLeft
                                 animations:^(void) {
                                     BOOL oldState = [UIView areAnimationsEnabled];
                                     [UIView setAnimationsEnabled:NO];
                                     [self.navigationController pushViewController:viewController animated:YES];
                                     [UIView setAnimationsEnabled:oldState];
                                 }
                                 completion:nil];
    
    0 讨论(0)
  • 2020-12-24 00:29
    - (void)viewWillDisappear:(BOOL)animated {
    [UIView beginAnimations:@"animation2" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration: 0.7];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
    [UIView commitAnimations]; }
    

    in the new viewcontroller will make it flip back the same way (instead of sliding left) when the back button in the toolbar is pushed -- make sure animation is enabled here, e.g., if you make a custom button to pop the stack, use:

    - (void) backToPrevious: (id) sender 
    {
        //[self.navigationController popViewControllerAnimated:YES];
        [self dismissModalViewControllerAnimated:YES];
    }
    
    0 讨论(0)
提交回复
热议问题