I want to put buttons on the view which has DragGesture by ZStack. But when I put buttons on the view, it doesn't work.
struct TmpView5: View {
@State var position: CGSize = CGSize(width: 200, height: 250)
var drag: some Gesture {
DragGesture()
.onChanged{ value in
self.position = CGSize(
width: value.startLocation.x
+ value.translation.width,
height: value.startLocation.y
+ value.translation.height
)
}
.onEnded{ value in
self.position = CGSize(
width: value.startLocation.x
+ value.translation.width,
height: value.startLocation.y
+ value.translation.height
)
}
}
var body: some View {
ZStack {
Rectangle()
.fill(Color.black)
.position(x: position.width, y: position.height)
.gesture(drag)
HStack {
Button(action: {
print("taped!!!")
}){
Image(systemName:"photo.on.rectangle")
}.padding(.trailing)
Button(action: {
print("taped!!!")
}){
Image(systemName:"a")
.padding(.trailing)
}
}
}
}
}
If I remove gesture(drag), I can tap buttons. Is it possible to add gesture on the Rectangle and enable buttons ?