Flip transition uinavigationcontroller push

2019-02-07 16:41发布

I am pushing a UIViewController in a navigation stack using the following code

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

Now when I press back I want it to do the same animation but its not working. Any idea why?

in ViewController.m

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

3条回答
疯言疯语
2楼-- · 2019-02-07 17:13

In Swift 4:

Push:

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

Pop:

  UIView.transition(with: (self.navigationController?.view)!, duration: 0.75, options: .transitionFlipFromLeft, animations: {
            self.navigationController?.popViewController(animated: true)
        })
查看更多
\"骚年 ilove
3楼-- · 2019-02-07 17:14

Actually the transition should be done like this

//MainView

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

// in viewcontroller

[UIView transitionWithView:self.navigationController.view
                  duration:0.75
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                animations:^{
                    [self.navigationController popToRootViewControllerAnimated:NO];
                }
                completion:nil];
查看更多
Emotional °昔
4楼-- · 2019-02-07 17:16
//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];
查看更多
登录 后发表回答