Transfrom layer with CATransform3D.

Init two views for each side, front and back.

label2 = UILabel(frame: .init(x: 0, y: 0, width: 200, height: 400))
label2.center = contentView.center
label2.textAlignment = .center
label2.text = "Yahoo 222"
label2.layer.zPosition = 1000
label2.backgroundColor = .blue
label2.isHidden = true
view.addSubview(label2)

label1 = UILabel(frame: .init(x: 0, y: 0, width: 200, height: 400))
label1.center = contentView.center
label1.textAlignment = .center
label1.text = "Yahoo 111"
label1.layer.zPosition = 1000
label1.backgroundColor = .red
label1.tag = 0
view.addSubview(label1)


This is example for basic way one of usages for 3d transform.

if (...) {
    let animate1 = CABasicAnimation(keyPath: "transform")
    animate1.fromValue = CATransform3DIdentity
    animate1.toValue = CATransform3DRotate(transform, -(90 * .pi / 180), 0, 1, 0)
    animate1.duration = 0.3

    CATransaction.begin()
    CATransaction.setCompletionBlock {
    self.label1.isHidden = true
    self.label2.isHidden = false
    }

    label1.layer.add(animate1, forKey: "transform")
    label1.layer.transform = animate1.toValue as! CATransform3D
    CATransaction.commit()

    let animate2 = CABasicAnimation(keyPath: "transform")
    animate2.fromValue = CATransform3DRotate(transform, -(270 * .pi / 180), 0, 1, 0)
    animate2.toValue = CATransform3DRotate(transform, -(360 * .pi / 180), 0, 1, 0)
    animate2.beginTime = CACurrentMediaTime() + 0.3
    animate2.duration = 0.3

    label2.layer.add(animate2, forKey: "transform")
    label2.layer.transform = animate2.toValue as! CATransform3D
} else {
    let animate2 = CABasicAnimation(keyPath: "transform")
    animate2.fromValue = CATransform3DRotate(transform, -(360 * .pi / 180), 0, 1, 0)
    animate2.toValue = CATransform3DRotate(transform, -(270 * .pi / 180), 0, 1, 0)
    animate2.duration = 0.3

    CATransaction.begin()
    CATransaction.setCompletionBlock {
    self.label2.isHidden = true
    self.label1.isHidden = false
    }

    label2.layer.add(animate2, forKey: "transform")
    label2.layer.transform = animate2.toValue as! CATransform3D
    CATransaction.commit()

    let animate1 = CABasicAnimation(keyPath: "transform")
    animate1.fromValue = CATransform3DRotate(transform, -(90 * .pi / 180), 0, 1, 0)
    animate1.toValue = CATransform3DIdentity
    animate1.beginTime = CACurrentMediaTime() + 0.3
    animate1.duration = 0.3

    label1.layer.add(animate1, forKey: "transform")
    label1.layer.transform = animate1.toValue as! CATransform3D
    CATransaction.commit()
}