I would like to adapt the position of one View (Rectangle) to another View (Button1). I only found solutions between a parent and a child-view or two child-views of the same parent view. Any tips how I could do that in this situation?
struct View: View {
var body: some View {
ZStack {
VStack {
Spacer()
HStack {
Spacer()
Button {} label: {
Text("1").foregroundColor(.white).padding().border(Color.white, width: 3).cornerRadius(5)
}
Spacer()
Button {} label: {
Text("2").foregroundColor(.white).padding().border(Color.white, width: 3).cornerRadius(5)
}
Spacer()
Button {} label: {
Text("3").foregroundColor(.white).padding().border(Color.white, width: 3).cornerRadius(5)
}
Spacer()
Button {} label: {
Text("4").foregroundColor(.white).padding().border(Color.white, width: 3).cornerRadius(5)
}
Spacer()
}
Spacer()
}
ZStack {
Color.black.opacity(0.5)
.ignoresSafeArea()
Rectangle() // adapt this Rectangle to the button
.cornerRadius(10)
.frame(width: 200, height: 200)
.blendMode(.destinationOut)
}
.compositingGroup()
}
.background(Color.blue)
}
}
edit: I want to align the rectangle with the button to code a tutorial.
Thanks a lot!