使用 SwiftUI 在 watchOS 中实现全屏视图

leo*_*lig 3 watchkit swiftui watchos-6

我不想将 SwiftUI 显示View为全屏watchOS(没有取消/后退按钮或时钟)

我尝试Sprite Kit Scene向视图添加 a 并设置.edgesIgnoringSafeArea(.all)但我仍然可以隐藏它们或将视图放在顶部栏下方。

Wes*_*uza 6

事实证明,即使使用 SwiftUI,它也能“工作”:

使用界面生成器: https://developer.apple.com/documentation/watchkit/wkinterfaceskscene/configuring_a_watchkit_scene_in_a_storyboard

使用 SwiftUI (watchOS 7):

@main
struct BitApp: App {
  @SceneBuilder var body: some Scene {
    WindowGroup {
      ContentView()
        .edgesIgnoringSafeArea(.all)
    }

    WKNotificationScene(controller: NotificationController.self, category: "myCategory")
  }
}
Run Code Online (Sandbox Code Playgroud)

删除NavigationView并使用edgesIgnoringSafeArea它就可以了!

编辑:它不会删除时钟,因为它将位于 SpriteKit 场景前面的角落。

  • 使用 Interface Builder,它仅适用于 SpriteKit 或 SceneKit,请尝试一下并看看。我编辑了我的答案以反映这一点。 (3认同)