uinavigationContoller(rootviewController:viewController())scenedelegate xcode 15.0通过编程方式

发布于 2025-02-07 07:51:05 字数 957 浏览 0 评论 0原文

我无法在屏幕上获得结果。 在此处输入图像描述 这是我在SceneDelegate SceneDelegate内部的代码的示例

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

   var window: UIWindow?
   
   func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let windowScene = (scene as? UIWindowScene) else { return }
    window = UIWindow(frame: windowScene.coordinateSpace.bounds)
    window?.windowScene = windowScene
    window?.rootViewController = UINavigationController(rootViewController: ViewController())
    window?.makeKeyAndVisible()
   }
}

不幸的是,我无法获得预期的结果。 在此处输入图像描述 请帮助我了解SceneDelegate内部使用UinavController制作应用程序的结构。我正在学习只能以编程方式而没有故事板 Xcode的版本为15.0

I can't get a result like in the screenshoot. enter image description here
Here is an example of my code inside of SceneDelegate

SceneDelegate

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

   var window: UIWindow?
   
   func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let windowScene = (scene as? UIWindowScene) else { return }
    window = UIWindow(frame: windowScene.coordinateSpace.bounds)
    window?.windowScene = windowScene
    window?.rootViewController = UINavigationController(rootViewController: ViewController())
    window?.makeKeyAndVisible()
   }
}

Unfortunately I can't get the expected result. enter image description here
Please help me to understand the structure of making app with UiNavController inside SceneDelegate. I'm learning to make the apps only programmatically without StoryBoard
Version of Xcode is 15.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

被翻牌 2025-02-14 07:51:05
 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let scene = (scene as? UIWindowScene) else { return }
        window = UIWindow(windowScene: scene)
        window?.overrideUserInterfaceStyle = .light // for light mode supported only 
        window?.rootViewController = BaseNavigationController(rootViewController: ViewController())
        window?.makeKeyAndVisible()
    }

基本导航controller是

import UIKit

class BaseNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        if #available(iOS 15.0, *) {
            let navigationBarAppearance = UINavigationBarAppearance()
            navigationBarAppearance.configureWithDefaultBackground()
            navigationBarAppearance.backgroundImage = UIImage(named: "NavBarBg") // if wanna add bg image 
            navigationBarAppearance.backgroundColor = .white // white bar color
            
            UINavigationBar.appearance().standardAppearance = navigationBarAppearance
            UINavigationBar.appearance().compactAppearance = navigationBarAppearance
            UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
            navigationBar.tintColor = .white
            navigationBar.isTranslucent = false
        }
    }
}
 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let scene = (scene as? UIWindowScene) else { return }
        window = UIWindow(windowScene: scene)
        window?.overrideUserInterfaceStyle = .light // for light mode supported only 
        window?.rootViewController = BaseNavigationController(rootViewController: ViewController())
        window?.makeKeyAndVisible()
    }

the base navigationController is

import UIKit

class BaseNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        if #available(iOS 15.0, *) {
            let navigationBarAppearance = UINavigationBarAppearance()
            navigationBarAppearance.configureWithDefaultBackground()
            navigationBarAppearance.backgroundImage = UIImage(named: "NavBarBg") // if wanna add bg image 
            navigationBarAppearance.backgroundColor = .white // white bar color
            
            UINavigationBar.appearance().standardAppearance = navigationBarAppearance
            UINavigationBar.appearance().compactAppearance = navigationBarAppearance
            UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
            navigationBar.tintColor = .white
            navigationBar.isTranslucent = false
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文