zPosition不粘住

时间:2018-06-20 13:32:15

标签: ios uikit core-animation

给出:     cardview是具有其自身层次结构的根UIView     条形码图像视图是Foo的(第一个)UIImageView子视图,带有条形码图像           初始zPosition为-1

我想要什么:     我在绕着Y轴翻转Foo时要显示Bar(实际上是Foo的后尺寸)

    let targetTransform: CATransform3D!
    var targetZposition: CGFloat!
    if CATransform3DIsAffine(self.cardView.layer.transform) {
        targetTransform = CATransform3DMakeRotation(.pi,0,1.0,0.0)
        targetZposition = 1
    } else
    {
        targetTransform = CATransform3DIdentity
        targetZposition = -1
    }
    CATransaction.begin()
    CATransaction.setAnimationDuration(.slow)
    UIView.animate(withDuration: .slow, animations: {
        self.cardView.layer.transform = targetTransform
        // this does not animate zPosition smoothly: self.cardView.barcodeImageView.layer.zPosition = targetZposition
    }, completion: { finished in
  //uncomment this hack is you love flicker            if finished {
  //                self.cardView.barcodeImageView.layer.zPosition = tar. getZposition
  //            }
    })
    let zAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.zPosition))
    zAnimation.fromValue = self.cardView.barcodeImageView.layer.zPosition
        //-targetZposition
    zAnimation.toValue = targetZposition
    print("from \(zAnimation.fromValue) to \(zAnimation.toValue)")
    zAnimation.duration = .slow
    self.cardView.barcodeImageView.layer.add(zAnimation, forKey: #keyPath(CALayer.zPosition))

    CATransaction.commit()

期望zPosition可以从-1平滑地动画到1 (或从1到-1),并且在视图翻转的一半时,backsize应该会通过

这不起作用。 backsize似乎短暂出现 然后以某种方式消失(动画完成后返回-1)?

我敢肯定有一种更简单的方法。

我要避免的是并排的UIView.transition 收据

希望这是可以理解的

0 个答案:

没有答案