gpt4 book ai didi

ios - 安全区域的 Root View Controller 偏移问题

转载 作者:行者123 更新时间:2023-12-01 18:34:02 26 4
gpt4 key购买 nike

当 Root View Controller 出现时, View 似乎与安全区域冲突
enter image description here
但是当我更改选项卡并再次返回此选项卡时,似乎一切正常
enter image description here
编辑:

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()

}}
搜索项约束
用户个人资料与搜索项具有相同的顶部。
enter image description here
TabViewController 设置代码
    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
} }

最佳答案

尝试使用 insetsLayoutMarginsFromSafeArea 从 safeArea 指定 View 插图布局属性(property):

rootVC.view.insetsLayoutMarginsFromSafeArea = true

关于ios - 安全区域的 Root View Controller 偏移问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63952067/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com