ios – Faucet anyplace so as to add a number of gadgets on canvas

[ad_1]

You solely have a singular location, so just one merchandise will ever seem in your instance. To have a number of gadgets, you may want some type of assortment, like an Array.

The next is a pared-down instance displaying utilizing an array:

struct Hammer: Identifiable {
    var id = UUID()
    var location: CGPoint
}

struct Level1: View {
    @State var hammers: [Hammer] = [] //<-- Begin with `none`
    
    var physique: some View {
        ZStack {
            ForEach(hammers) { hammer in // Show all the hammers
                Picture(systemName: "hammer.fill")
                    .resizable()
                    .body(width: 30, top: 30)
                    .place(hammer.location)
            }
        }
        .body(maxWidth: .infinity, maxHeight: .infinity)
        .contentShape(Rectangle())
        .gesture(DragGesture(minimumDistance: 0).onEnded { worth in
            self.hammers.append(Hammer(location: worth.location)) // Add a Hammer
        })
        .edgesIgnoringSafeArea(.all)
    }
}

Notice: I am unclear on what the GeometryReader is for in your code — you declare it, then use UIScreen dimensions — usually in SwiftUI we simply use GeometryReader

[ad_2]

Leave a Reply