Flipping Views in SwiftUI

Viewed 71

In my SwiftUI app, I have an Image:

enter image description here

I added this image using:

Image("shoe_test")
 .resizable()
 .frame(width: 275, height: 275)
 .rotationEffect(Angle(degrees: 30))

However, I would like to flip this image in the opposite direction, like:

Image 2

For this, I haven't tried anything, but I had no luck with rotationEffect, and I can't get my head over this, Any help is greatly appreciated,

2 Answers

You could use

.rotation3DEffect(.degrees(180), axis: (x: 0, y: 1, z: 0))

documentation

With the rotation3DEffect you can rotate your image in all 3 Dimensions.

  • rotating along the x axis will flip the image top/bottom
  • rotating along the y axis will mirror it right/left
  • rotating along the z axis will flip and mirror it.

It can be done with scale

.scaleEffect(x: -1, y: 1)  // flip horizontally

.scaleEffect(x: 1, y: -1)  // flip vertically
Related