SwiftUI:在tvOS上获取当前关注的NavigationView项目索引

时间:2020-06-22 09:53:01

标签: swift swiftui tvos navigationview

我正在使用SwiftUI构建tvOS应用。这是它的外观:

enter image description here

我希望顶部绿色标签显示当前关注的元素数。

代码如下:

Text(selection ?? "no value").background(Color.green)

NavigationView {
  ScrollView(.horizontal) {
    HStack{

       VStack {
          NavigationLink(destination: view2, tag: "1", selection: $selection) {
              Image("placeholder").scaledToFit().frame(width:300, height: 170) }
              Text("Button").foregroundColor(Color(.white)).padding(.top,10)
       } 
       
       VStack {
          NavigationLink(destination: view2, tag: "1", selection: $selection) {
              Image("placeholder").scaledToFit().frame(width:300, height: 170) }
              Text("Button").foregroundColor(Color(.white)).padding(.top,10)
       } 

       ...
      
       }.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .bottomLeading)
    }
 }

我应该如何实现呢?

0 个答案:

没有答案