Showing two UIViewController at the same time

邮差的信 提交于 2019-12-11 18:49:47

问题


I have two UIViewControllers which I sometimes need to show at the same time. Imagine ViewController A only has one button and is otherwise transparent. Once I touch the button I would like ViewController B (which is green) to fade in and do other custom animations, but ViewController A (and the button) needs to be still shown on top of B. Once the fade/animation etc. are over, only ViewController B (green) is visible.

My questions:

1) What is the best setup? UINavigationController with hidden NavBar doesn't make much sense. TabBarController with hidden TabBar strikes me as equally odd as I don't need the TabBar. 2) I'm a bit confused about views and windows. The window is init'ed in my AppDelegate and then I would add a RootViewController:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] init];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

If I want to have two ViewController's views on top of each other as described above, would I need to add the view of ViewController B (the green one) to ViewController A (the one with the button)? Do I need to swap the rootViewControllers?

Ideally, I don't want to take care of all the ViewDidAppear's of VC A and B, so I guess UINavigationController/TabBar would not be a bad idea after all, if I could customise the transitions between Controllers.


Edit:

I really need two different VCs as I would do more complex things than just display a button, like having a scrollview in VC A and another scrollview in VC B. I don't want to have two scrollviews (or tableViews etc.) in one VC as this gets messy.


回答1:


The best way is to have only one view controller. View A will just sit on top of B until you fade it out.



来源:https://stackoverflow.com/questions/9683554/showing-two-uiviewcontroller-at-the-same-time

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