Post

Replies

Boosts

Views

Activity

Reply to How to set zIndex inside VStack and HStack
Hi Claude. Thanks for your reply. Here is a smaller code example that illustrates my problem. I'm using nested VStacks and HStacks to get the 3x3 grid layout I desire. If I select an image in row 1 it will jump to the front of all other images on row 1 but not in front of images on row 2 or row 3. If I select a card on row 2 it will jump in front of cards on row 1 and 2 but not 3. If I select a card on row 3 it jumps in front of all cards on the screen. I'd like to bring any card, regardless of what row it is in to the front of the screen. I'm very new to swift so maybe this is not something that can be done using this layout. If not what is the approach I should use. Thanks struct MyObject: View {   @State var dragAmount = CGSize.zero   var myImage: Image = Image("myImage")   var body: some View {     myImage     .resizable()     .frame(width: 100, height: 150)     .offset(dragAmount)     .zIndex(dragAmount == .zero ? 0 : 1)     .gesture(       DragGesture(coordinateSpace: .global)         .onChanged {           self.dragAmount = CGSize(width: $0.translation.width, height: $0.translation.height)         }         .onEnded {           _ in           self.dragAmount = .zero         })   } } struct ContentView: View {   var body: some View {     VStack () {       ForEach(0..<3) { row in         HStack {           ForEach(0..<3) { col in             MyObject()           }         }       }     }   } }
Feb ’23