出现根视图控制器时,该视图似乎与安全区域冲突
但是当我更改选项卡并再次回到该选项卡时,似乎一切正常
编辑:
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()
}}
搜索项的约束用户个人资料与搜索项的顶部相同。
最佳答案
尝试使用insetsLayoutMarginsFromSafeArea属性从safeArea指定视图插图布局:
rootVC.view.insetsLayoutMarginsFromSafeArea = true