iosswiftxcoderootviewcontroller

Root view controller offset issue from Safe Area


When root view controller appears, the view seems like conflicting with safe area

enter image description here

But when I change tab and come back again to this tab again, is seems like everything is ok

enter image description here

Edit:

class Switcher {

static func updateRootVC(){
    
    let status = UserDefaults.standard.object(forKey: "Accesstoken")
    let userID = UserDefaults.standard.object(forKey: "UserId")
    let userName = UserDefaults.standard.object(forKey: "UserName")
    let userImage = UserDefaults.standard.object(forKey: "UserImage")

    if let currentUser = userID {
        requestManager.instance.userID = currentUser as! Int
    }
    if let currentStatus = status {
        requestManager.instance.getToken = currentStatus as? String
    }
    if let Name = userName {
        Api.Params.inputUserName = (Name as? String)!
    }
    if let Image = userImage {
        Api.Params.inputUserImage = (Image as? String)!
    }
    
    
    var rootVC : UIViewController?

    if(status != nil){
        rootVC = UIStoryboard(name: "Tabbar", bundle: Bundle.main).instantiateViewController(withIdentifier: "Tabbar") as! UITabBarController
    } else {
        rootVC = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "welcome") as! UINavigationController
    }
    
    rootVC!.view.insetsLayoutMarginsFromSafeArea = true


    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    appDelegate.window?.rootViewController = rootVC
    appDelegate.window?.makeKeyAndVisible()
    
}}

Contraints of search items

user profile has the same top as search items.

enter image description here

TabViewController setup Code

    func setupTabbar(){
    if Api.Params.isGuest == true {
        let vc1 = storyboardTabbar.instantiateViewController(withIdentifier: "home") as! UINavigationController
        let vc2 = storyboardTabbar.instantiateViewController(withIdentifier: "favorite") as! GuestVC
        let vc3 = storyboardTabbar.instantiateViewController(withIdentifier: "scanner") as! ScannerVC
        let vc4 = storyboardTabbar.instantiateViewController(withIdentifier: "history") as! GuestVC
        let vc5 = storyboardTabbar.instantiateViewController(withIdentifier: "settings") as! GuestVC
        self.viewControllers = [vc1 , vc2 , vc3 , vc4 , vc5]
        self.selectedViewController = vc1

    } else if Api.Params.isLanguageChange == true{
        Api.Params.isLanguageChange = !Api.Params.isLanguageChange
        let vc1 = storyboardTabbar.instantiateViewController(withIdentifier: "home") as! UINavigationController
        let vc2 = storyboardTabbar.instantiateViewController(withIdentifier: "fav") as! UINavigationController
        let vc3 = storyboardTabbar.instantiateViewController(withIdentifier: "scanner") as! ScannerVC
        let vc4 = storyboardTabbar.instantiateViewController(withIdentifier: "his") as! UINavigationController
        let vc5 = storyboardTabbar.instantiateViewController(withIdentifier: "set") as! UINavigationController
        self.viewControllers = [vc1 , vc2 , vc3 , vc4 , vc5]
        self.selectedViewController = vc5
    } else {
        let vc1 = storyboardTabbar.instantiateViewController(withIdentifier: "home") as! UINavigationController
        let vc2 = storyboardTabbar.instantiateViewController(withIdentifier: "fav") as! UINavigationController
        let vc3 = storyboardTabbar.instantiateViewController(withIdentifier: "scanner") as! ScannerVC
        let vc4 = storyboardTabbar.instantiateViewController(withIdentifier: "his") as! UINavigationController
        let vc5 = storyboardTabbar.instantiateViewController(withIdentifier: "set") as! UINavigationController
        self.viewControllers = [vc1 , vc2 , vc3 , vc4 , vc5]
        self.selectedViewController = vc1
    } }

Solution

  • After so many days , finally found out that top constraint to safeArea cause the issue , changing that to Superview done the trick

    enter image description here