0

I want to create a loading view page to put on top of all the views in screen. I use the following code to get the rootViewController's view:

UIApplication.sharedApplication.keyWindow.rootViewController.view 

I create my view page and add it as a subview to rootViewController's view. My problem is when I do this, if the rootViewController changes, my loading page will go behind the new viewController's view. For example, I am calling the showLoading function when I send an http request. When response comes back, it changes the viewController and loading goes behind it. Is there any way to put my loading on top independent from what happens in the background?

1 Answer 1

3

You are allowed to create as many UIWindows as you'd like. If you really want to ensure a view will always be on top, then its best to create a second UIWindow and add it your the hierarchy. Then regardless of what happens in the other UIWindow your loading indicator will remain on top.

Example

UIWindow *secondWindow = [[UIWindow alloc] initWithFrame:[[[UIApplication sharedApplication] keyWindow] frame]]; [secondWindow setWindowLevel:UIWindowLevelStatusBar]; [secondWindow makeKeyAndVisible]; UIViewController *aNewViewController = [[UIViewController alloc] initWithFrame:secondWindow.bounds]; [secondWindow setRootViewController:aNewViewController]; 
Sign up to request clarification or add additional context in comments.

4 Comments

Thats a great Idea. But how can I add the UIWindow to the hierarchy?
Just create one and makeKeyAndVisible
Damn, what if I want to put one on top of that?? (Just joking)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.