我是 Swift/SwiftUI 新手,想知道如何从嵌套子视图中消除模式/页面。
\n首先,我从 Flutter、UIHostingController、然后 SwiftUI 页面调用。(当前显示为模态...)
\n导航到 SwiftUI 后,我无法从子视图中使用 @environment 数据。
有什么办法可以做到这一点吗?\n提前致谢。
\nAppDelegate.swift
\n@UIApplicationMain\n@objc class AppDelegate: FlutterAppDelegate {\n override func application(\n _ application: UIApplication,\n didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?\n ) -> Bool {\n let controller : FlutterViewController = self.window?.rootViewController as! FlutterViewController\n let channel = FlutterMethodChannel.init(name: "com.example.show", binaryMessenger: controller.binaryMessenger)\n channel.setMethodCallHandler({\n (call, result) -> Void in\n if call.method == "sample" {\n let vc = UIHostingController(rootView: ContentView())\n vc.modalPresentationStyle = .fullScreen\n controller.present(vc, animated: true,completion: nil)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n
Run Code Online (Sandbox Code Playgroud)\n内容视图.swift
\nstruct ContentView: …
Run Code Online (Sandbox Code Playgroud)