Flip ViewController but maintain same NavigationController with Storyboard

此生再无相见时 提交于 2020-01-05 09:56:13

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/16787843/flip-viewcontroller-but-maintain-same-navigationcontroller-with-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!