【问题标题】:SwiftUI: how to keep single toolbar or ToolbarItem on the next view in NavigationView stack?SwiftUI:如何在 NavigationView 堆栈的下一个视图上保留单个工具栏或 ToolbarItem?
【发布时间】:2022-10-07 21:35:40
【问题描述】:

应用于 NavigationView 目标的每个工具栏实际上都是单独的工具栏,并且一个工具栏正在更改为具有不透明度过渡的另一个工具栏。

如何在下一个目标上保留一个工具栏或仅 ToolbarItem,因此它可以是动画的,例如,假设尾随 ToolbarItem 在 HStack 中包含 2 个按钮,我想插入另一个带有动画的按钮,就像我在一个单视图?

想要完全控制 ToolbarItem,就像它是单个项目一样。

struct Temp_Preview: PreviewProvider {
    static var previews: some View {
        return NavigationView {
            NavigationLink {
                Text("TARGE TPAGE")
                    .toolbar {
                        ToolbarItem(placement: .navigationBarTrailing) {
                            ToolBarView(showExtraButton: true)
                        }
                    }
            } label: {
                Text("Next page")
                    .toolbar {
                        ToolbarItem(placement: .navigationBarTrailing) {
                            ToolBarView(showExtraButton: false)
                        }
                    }
            }

        }
        .navigationViewStyle(StackNavigationViewStyle())
    }
}

struct ToolBarView: View {
    let showExtraButton: Bool
    var body: some View {
        HStack {
            let buttonsCount = showExtraButton ? 3 : 2
            ForEach(0..<buttonsCount, id: \.self) { index in
                Button(action: {}) {
                    Color.blue
                        .cornerRadius(5)
                        .frame(width: 80 - CGFloat(20 * index), height: 20)
                }
            }
        }
    }
}

【问题讨论】:

    标签: swift swiftui navigationview


    【解决方案1】:

    你是怎么固定id的?我也有同样的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-28
      • 2021-07-02
      • 1970-01-01
      • 2021-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多