I am trying to fit an Image into a ZStack after rotating the image. The width and height of the ZStack frame is 300x200. I want to fit the image into that ZStack even after the image is being rotated.
struct ContentView: View {
@State private var rotationAngle: Double = 0.0
var body: some View {
VStack{
Spacer()
ZStack {
Image("dummy-img")
.resizable()
.scaledToFit()
.rotationEffect(Angle(degrees: rotationAngle))
.padding()
}
.frame(width: 300, height: 200)
.border(.black, width: 2)
Spacer()
Button{
rotationAngle = 90.0
} label: {
Text("Rotate Image").padding().background(Color.gray).foregroundColor(Color.white)
}
Spacer()
}
}
}