iosswiftuiview3dcatransition

Swift 4 CATransition flipping UIView without 3D effect


I wanna flip an UIView in a ViewController without the 3D effect, is it possible to do that?

let transition = CATransition()
transition.duration = 0.5
transition.type = "flip"
transition.subtype = kCATransitionFromLeft

view.layer.add(transition, forKey: kCATransition)

Solution

  • I have a solution to propose if it suits your needs. Instead of going with the rotation parameter you could play with the scale. You will have a faked rotation with no perspective whatsoever.

    Scale x for horizontal flip and Scale y for vertical.

    You can do this as follow in view did load (or the button action function if you use a button to trigger the animation) :

    UIView.animate(withDuration: 0.5) {
            self.yourViewName.transform = CGAffineTransform(scaleX: -1, y: 1)
        }
    

    I hope it can help you.