10

Looks like you can rotate a view upside down with UIView, but I can't find anything saying it's possible to do the same thing with a SwiftUI View.

Any help will be appreciated :)

Lemon
  • 1,184
  • 11
  • 33

4 Answers4

21

Actually approach is the same to referenced post

demo

Text("Test").font(.largeTitle)
    .scaleEffect(CGSize(width: 1.0, height: -1.0))  // << here !!
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Asperi
  • 228,894
  • 20
  • 464
  • 690
2

Here is a convenience extension:

extension View {
    func flipped(_ axis: Axis = .horizontal, anchor: UnitPoint = .center) -> some View {
        switch axis {
        case .horizontal:
            return scaleEffect(CGSize(width: -1, height: 1), anchor: anchor)
        case .vertical:
            return scaleEffect(CGSize(width: 1, height: -1), anchor: anchor)
        }
    }
}

Use it:

Text("Flip me")
    .flipped(.vertical)
Paul B
  • 3,989
  • 33
  • 46
0

Rotate Image As Mirror image by SwiftUI:

struct Rotate3DView: View {
    @State var imagename: String = "exImage"

     var body: some View {

       VStack {
           ZStack{
               
               Image(imagename).resizable().opacity(0.3)
                   .rotation3DEffect(.degrees(180), axis: (x: -10, y: 0, z: 0))
                   .rotationEffect(.radians(.pi))
                   .padding(.top,60)
                   .cornerRadius(5)
                   .frame(width: 180, height: 280)

               Image(imagename).resizable().padding(.bottom,45).frame(width: 180, height: 280)
                  
                  
           }

       }
     }
   }

This is very easy for native Users.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 20 '22 at 10:18
-2

Turns out I can just apply this to the surrounding Stack:

.rotationEffect(.degrees(-180))

To flip it vertically

Lemon
  • 1,184
  • 11
  • 33