0

SwiftUI では、初期起動ビューが Scene Delegate に依存していることを理解しています。したがって、次のようなものがあります。

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

        // Create the SwiftUI view that provides the window contents.
        //let contentView = ContentView() //only uncomment when messing with user db
        let contentView = FirstView()
       // let contentView = BarView(value: 3)

        // Use a UIHostingController as window root view controller.
        if let windowScene = scene as? UIWindowScene {
            let window = UIWindow(windowScene: windowScene)
            window.rootViewController = UIHostingController(rootView: contentView)
            self.window = window
            window.makeKeyAndVisible()
        }
    }

私は本質的に、Swift に contentView の rootView を開くように指示しています。これは、この場合は FirstView() に相当します。これは、アプリが以前に閉じられた (つまり、バックグラウンドで実行されていない) と仮定して、アプリを開くたびに実行されます。

ただし、アプリがバックグラウンドで実行されている場合 (つまり、iPad などでホーム ボタンを 1 回押すだけ)、ユーザーが再びアプリを開くと、アプリケーションはユーザーが最後に表示したビューを記憶し、それを再開します。この動作を変更する方法はありますか? アプリがバックグラウンドで実行されているときにユーザーがアプリケーションを開いたときに、ビューが特定のビューに変更されるように、Scene Delegate を変更する方法はありますか?

ありがとう。

4

1 に答える 1