Flip ViewController but maintain same NavigationCo

2019-08-09 13:56发布

I'm trying to flip the viewcontroller inside navigationcontroller but with little success so far, I tried thousands of solutions but none suited. I want to flip the controller like this:

Press button to go on the map: http://i39.tinypic.com/fabul3.jpg

Press same button to go back with change image: http://i40.tinypic.com/2qa1y0h.jpg

I need to mantain the coerence with storyboard for segue. Do you have any idea or example of how to do this?

2条回答
Summer. ? 凉城
2楼-- · 2019-08-09 14:47

Rather than flipping the view controller, you may find it easier to transition the view itself. There's a standard way to flip views, which is covered in this question:

How to implement flip transition effect for UIView

Alternatively, you could always try and transition the view controller itself through a custom segue, but I suspect it will be much easier to handle the flip at a UIView level.

查看更多
Viruses.
3楼-- · 2019-08-09 14:51

You can create a new UIViewController which contains a container view in the Storyboard, and assign the train network map view controller to the container view.

Then in the code you can instantiate the map view controller from the storyboard:

self.mapViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MapViewController"];

Read up more on container view to understand on the following lines, assuming networkMapViewController is the initial view controller that you want to flip into mapViewController:

[self.networkMapViewConroller willMoveToParentViewController:nil];
[self addChildViewController:self.mapViewController];
[self.mapViewController didMoveToParentViewController];

Then you can make use of view controller method transitionFromViewController:toViewController:duration:options:animations:completion:

[self transitionFromViewController:self.networkMapViewController
                      toViewController:self.mapViewController
                              duration:.5
                               options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionTransitionFlipFromRight
                            animations:nil
                            completion:^(BOOL finished) {
                                [self.networkMapViewController removeFromParentViewController];
                            }];

You will need to code similar lines for change back from map view controller to networkMapViewController.

查看更多
登录 后发表回答