与视图交互会使工具栏和标题消失

Interacting with view makes toolbar & title disappear

提问人:szagun 提问时间:10/2/2023 最后编辑:jonrsharpeszagun 更新时间:10/5/2023 访问量:41

问:

我正在开发一个需要从 iPhone 接收图像的 Watch 应用程序。该应用程序的用户需要解放双手,这就是为什么他们必须在 Watch 上检查这些图像的原因。因此,我添加了一个基本的图像查看器,允许他们放大图像并四处平移。

一旦用户平移或缩放,工具栏和标题就会消失。我在模拟器和我同事的手表 (A2376) 上观察到了这种行为,但在我的手表 (A2356) 上没有观察到这种行为。在 watchOS 9.6.2 和 10.0.1 上均进行了测试。

为什么会这样?

下面是一些示例代码:

// View is presented on a sheet

TabView(selection: $viewing) {
    ForEach(images) { reference in
        reference.img
            .resizable()
            .aspectRatio(contentMode: .fit)
            .scaleEffect(scale)
            .offset(offset + draggingOffset)
            .frame(width: screenSize.width, height: screenSize.height-1)
            .clipped()
            .id(reference.id)
            .gesture(panGesture, including: .gesture)
            .gesture(tapZoomGesture)
            .navigationTitle(viewerTitle)
            .focusable()
            .digitalCrownRotation(detent: $scale,
                                  from: 0.5,
                                  through: scaleMax,
                                  by: 0.1,
                                  sensitivity: .low,
                                  isContinuous: false,
                                  isHapticFeedbackEnabled: false,
                                  onIdle: { offset = stickyEdgeOffset })
    }
}
Swift SwiftUI Apple-Watch 手表

评论


答:

0赞 szagun 10/5/2023 #1

解决方案正在提升和 .我真的很幸运地猜到了。无法想象它应该像这样工作。navigationTitletoolbar

someView
  .sheet(isPresented: $isShowingViewer, content: {
    imageViewer
      .navigationTitle("Image viewer")
      .toolbar(content: {
          ToolbarItem(placement: .confirmationAction, content: {
              imageViewerToolbar
        })
    })
})