In order to perform a flip animation with one image changing into another, I have a two-layer UIView (tried also UIView with two subviews - the same problem) rotating around X (or Y) axis in 3D.
When rotation angle is below pi/2 the top layer hides bottom layer which is OK, however with angle between pi/2 and pi I expect to see the bottom layer.
In fact the top layer is always seen no matter of the rotation angle, though both layers are all right, as if I hide top layer, I can see the bottom layer all the way.
It looks like a stiff design from Apple, or maybe I miss something. So far I have to do the animation manually for nothing better available.
This is the (simplified) code for someone who may wish to try:
let frame = CGRect(origin: CGPoint(), size: spriteSize)
let sprite = UIView(frame: frame)
sprite.isHidden = true
let bottomLayer = CALayer()
bottomLayer.frame = frame
bottomLayer.contents = UIImage(named:"name1.png")!.cgImage
bottomLayer.transform = CATransform3DMakeScale(-1, 1, 1)
sprite.layer.addSublayer(bottomLayer)
let topLayer = CALayer()
topLayer.frame = frame
topLayer.contents = UIImage(named:"name2.png")!.cgImage
sprite.layer.addSublayer(topLayer)
parent.addSubview(sprite)
sprite.layer.position = fromPosition
sprite.isHidden = false
UIView.animate(withDuration: 3, delay: 0,
animations:{
sprite.layer.transform =
CATransform3DConcat(
CATransform3DMakeRotation(CGFloat.pi, 1, 0, 0))
sprite.layer.position = targetPosition
})