22

I know it's probably a dummy question, but I have to ask: How to flip a UIView vertically? I'm not asking for doing a animation, but just flip it.

I can do vertical flip a UILabel by:

label1.layer.transform = CATransform3DMakeRotation(M_PI, 1.0f, 0.0f, 0.0f);

and turn it back by:

label1.layer.transform = CATransform3DMakeRotation(M_PI, 0.0f, 0.0f, 0.0f);

But when I'm doing it to a view:

self.view.layer.transform = CATransform3DMakeRotation(M_PI, 1.0f, 0.0f, 0.0f);

I think it only rotate half way... So, any ideas?

Thanks guys.

Eimantas
  • 48,927
  • 17
  • 132
  • 168
user966422
  • 231
  • 1
  • 2
  • 3

1 Answers1

54

I realize this is an old question, but I'll leave this here anyway. The following would flip the view vertically using just the y-scale of the layer, so it would be my preference:

self.view.layer.transform = CGAffineTransform(scaleX: 1, y: -1)
Community
  • 1
  • 1
Mathew
  • 1,788
  • 15
  • 27
  • 4
    I see you miss the code, if self is kind of UIView, you can use `self.transform = CGAffineTransform(scaleX: 1, y: -1)` if you want to use layer.transform, it is kind of CATransform3D, so the code is `self.layer.transform = CATransform3DMakeScale(1, -1, 1)` – QuangLoc Dec 11 '20 at 04:53