tvOS + SwiftUI在各节之间聚焦

问题描述

我已经建立了一个非常简单的SwiftUI tvOS应用程序。我很难使用Focus引擎。当应用启动时,它专注于可以理解的“启动”。向下滑动,转到StackView。在项目之间向左/向右滑动效果很好。除了无论在哪里尝试,我都无法向上滑动以启动Launch。

目标是向上滑动,应始终转到“启动”按钮(将焦点放在单元格上会更改上面的内容

在这里犯错了吗?我的印象是我没有做任何特别或复杂的事情。谢谢

enter image description here

这是我的代码


struct ContentView: View {
    @Observedobject private var viewmodel = Environmentsviewmodel()
    @State private var currentEnvironment: Environment?
    var environments: [Environment]?

    var body: some View {
        GeometryReader { geometry in
            vstack(spacing: 50) {
                BannerView(environment: currentEnvironment)
                    .frame(height: geometry.size.height * 0.6)
                    .clipped()

                ScrollView(.horizontal,showsIndicators: false) {
                    HStack(alignment: .center,spacing: 50) {
                        ForEach(environments ?? viewmodel.environments) { environment in
                            Button(action: {
                                currentEnvironment = environment
                            }) {
                                EnvironmentCard(title: environment.title,subtitle: "Coming Soon",image: environment.image,isFocused: environment.title == currentEnvironment?.title)
                                    .frame(width: 500,height: geometry.size.height * 0.4)
                                    .edgesIgnoringSafeArea(.all)
                            }
                            .buttonStyle(PlainButtonStyle())
                        }
                    }
                }
                .padding(.leading,50)
                .padding(.trailing,50)
                .frame(height: geometry.size.height * 0.4)
            }
            .edgesIgnoringSafeArea([.top,.leading,.trailing])
            .onAppear {
                self.viewmodel.fetch()
            }
        }
    }
}
struct BannerView: View {
    var environment: Environment?

    var body: some View {
        GeometryReader { geometry in
            ZStack {
                if let environment = environment,let url = URL(string: environment.image) {
                    URLImage(url,placeholder: Image("Placeholder")) { proxy in
                        proxy.image
                            .resizable()
                            .aspectRatio(contentMode: .fill)
                    }
                    .edgesIgnoringSafeArea(.all)
                        .frame(height: geometry.size.height)
                } else {
                    Color.darkGray.edgesIgnoringSafeArea(.all)
                }

                vstack(alignment: .leading,spacing: 10) {
                    Spacer()
                    Text(environment?.title ?? "Title")
                    Text("Description")
                    Button("Launch",action: {})
                }
                .frame(maxWidth: .infinity,alignment: .leading)
                .padding(.leading,50).padding(.bottom,50)
            }
            .frame(height: geometry.size.height)
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)