I have a face shape drawn in swiftUI. The face is a circle and eyes are two circles. I want to group these three Circles as one Single shape so that when I move face shape the eyes also should move with the face also I want to draw the eyes based on relative face circle coordinate and not the coordinate system of rect of draw func.
Something like this
struct ContentView: View {
@State var x: CGFloat = 100
@State var y: CGFloat = 100
var body: some View {
VStack{
//Shape Group
Group{
//Put your Shape here
ZStack{
Rectangle().fill(Color.green)
Circle().fill(Color.blue)
}.frame(width: 100, height: 100, alignment: .center )
}
.position(x: self.x, y: self.y)
//Slider for position
HStack{
Text("x: \(x)")
Slider(value: $x, in: 0...400, step: 1).padding(.horizontal, 10)
}
HStack{
Text("y: \(y)")
Slider(value: $y, in: 0...500, step: 1).padding(.horizontal, 10)
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.