4

In my AppDelegate.swift I check if the user is signed in or not

if let currentUser = Auth.auth().currentUser{
    self.window?.rootViewController = self.storyboard?.instantiateViewController(withIdentifier: "HomeScreen")
}else{
    self.window?.rootViewController = self.storyboard?.instantiateViewController(withIdentifier: "LoginScreen")
}

If the user is not logged they get redirected to LoginScreen and there they can login, I then present HomeScreen as follows

UIApplication.shared.keyWindow?.window?.rootViewController = self.storyboard?.instantiateViewController(withIdentifier: "HomeScreen")

My HomeScreen is a NavigationController that will redirect to a ViewController, there I add my view as follows:

UIApplication.shared.keyWindow?.addSubview(newView!)

When my app runs directly to my HomeScreen from the AppDelegate newView will display above my StatusBar, like it should. If the HomeScreen is displayed after a user login from the LoginScreen, newView will be displayed behind the statusBar.

What can be the problem that makes my view display below the status bar in the second scenario?

EDIT: I might also add that the newView is a swipe gesture to show it.

This is how it looks when a user login through LoginScreen

This is how it should look and does when you get redirected to HomeScreen from AppDelegate.swift

Naresh
  • 16,698
  • 6
  • 112
  • 113
Dridia
  • 183
  • 15
  • Why do you add the new view directly to the window? Why not set it as the rootview of the viewcontroller? – rodskagg May 16 '18 at 18:20
  • With status bar, do you mean the small bar with the WiFi strength and battery indicator symbols? If not, would posting (partial) screenshots of the two situations be an option? – Rein Spijkerman May 16 '18 at 18:46
  • @andlin This will result in the view being behind both the statusbar and the navigationbar. – Dridia May 16 '18 at 19:25
  • @ReinSpijkerman Indeed, that is exactly what i mean. I want the new to be above the statusbar. – Dridia May 16 '18 at 19:25
  • Have you tried setting UIApplication.shared.keyWindow?.windowLevel = UIWindowLevelStatusBar+1 ? – rodskagg May 16 '18 at 19:34
  • What does the constraints for the view look like? – rodskagg May 16 '18 at 19:41
  • @andlin By setting the statusbar level to +1, the entire statusbar text will disappear. I add the view programatically on x = y = 0. – Dridia May 16 '18 at 19:43
  • Yeah, I better understand the problem now that you've added screenshots. I misunderstood what you were trying to do earlier. It looks like the top of the view is cut off, with the top part hidden beneath the status bar. What happens if you do: UIApplication.shared.keyWindow?.bringSubview(toFront: newView!) after adding the view to the window? – rodskagg May 16 '18 at 19:59
  • @andlin I found out the problem. I set the statusbars background color in the LoginScreen. For some reason this resulted in the view behind hidden behind the statusbar. Thanks a lot for your time and help, I really appreciate it! – Dridia May 16 '18 at 20:12
  • 1
    No problem. Glad you found the solution! – rodskagg May 16 '18 at 20:19

0 Answers0