在SwiftUI中使用ForEach进行迭代时,如何确保视图出现在其他视图之上?

Notice the 'capsule' shape opening up to the right is under the green-purple bar.I have a SwiftUI view that is a circular view which when tapped opens up and is supposed to extend over the UI to its right. How can I make sure that it will appear atop the other ui? The other UI elements were created using a ForEach loop. I tried zindex but it doesn't do the trick. What am I missing?

ZStack {
  VStack(alignment: .leading) {
    Text("ALL WORKSTATIONS")
    ZStack {

      ChartBackground()

      HStack(alignment: .bottom, spacing: 15.0) {



        ForEach(Array(zip(1..., dataPoints)), id: \.1.id) { number, point in
          VStack(alignment: .center, spacing: 5) {



          DataCircle().zIndex(10)
          ChartBar(percentage: point.percentage).zIndex(-1)
          Text(point.month)
            .font(.caption)
        }
        .frame(width: 25.0, height: 200.0, alignment: .bottom)
        .animation(.default)
      }
    }
    .offset(x: 30, y: 20)
       }
      .frame(width: 500, height: 300, alignment: .center)
     }
   }
  }
}
评论
shawphy
shawphy

I did not test it but you can try wrapping your DataCircle inside a ZStack like:

ZStack {
    DataCircle().zIndex(100)
}
ChartBar(percentage: point.percentage).zIndex(-1)
Text(point.month).font(.caption)
点赞
评论