【问题标题】:TabView with PageTabViewStyle on tvOS navigationlink or buttons not workingtvOS 导航上带有 PageTabViewStyle 的 TabView 链接或按钮不起作用
【发布时间】:2020-11-19 03:49:57
【问题描述】:

在具有 PageTabViewStyle 的 TabView 的页面中,导航或 Button 的操作都不起作用。有人有任何想法或解决方法吗?复制代码:

var body: some View {
    VStack {
        TabView(selection: $selection) {
            Button(action: {
                print("First selected")
            }){
                Text("Fist")
            }
            .tag(0)
            .buttonStyle(PlainButtonStyle()
            Button(action: {
                print("Second selected")
            }){
                Text("Second").tag(1)
            }
            .tag(1)
            Button(action: {
                print("Third selected")
            }){
                Text("Third")
            }
            .tag(2)
        }
        .tabViewStyle(PageTabViewStyle(indexDisplayMode: .always))
        .frame(width: 900, height: 400)
        .background(Color.blue)
    }
}

【问题讨论】:

  • 如何把你的按钮放在一个 VStack 中

标签: swiftui tvos


【解决方案1】:

Button 操作在您的共享代码中有效,但问题在于 Button 的可点击区域,该区域非常少。 因此,您无法感知按钮操作。

像这样增加按钮的可点击区域:

Text("Fist")
      .frame(width: 200, height: 200, alignment: .center)
      .background(Color.red)

【讨论】:

    猜你喜欢
    • 2020-10-17
    • 1970-01-01
    • 1970-01-01
    • 2019-04-23
    • 1970-01-01
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 2020-11-01
    相关资源
    最近更新 更多