CAKeyframeAnimation比例

时间:2017-10-30 19:55:27

标签: ios swift calayer cakeyframeanimation

我不想使用keyframeAnimation来调整UIView的大小,因为它必须在标签文本关闭时与其同步动画。

所以我设置了大小动画

        let sizeAnimation = CAKeyframeAnimation(keyPath: "transform.scale")
        sizeAnimation.duration = 1.2

        let animationTime = TimeInterval(1.2/Float(volumeObjects.count - 1))
        // Stride is an inverted for in, it goes from volumeObjects count to 0

        var sizeAnimationValuesArray = [NSValue]()
        var keyTimes = [NSNumber]()
        var currentKeyTime: TimeInterval = 0
        for index in stride(from: volumeObjects.count - 1, to: -1, by: -1) {

            let currentPercentage = CGFloat(index)/CGFloat(volumeObjects.count)
            sizeAnimationValuesArray.append(NSValue(caTransform3D: CATransform3DMakeScale(1.0, currentPercentage, 1.0)))
            keyTimes.append(NSNumber(value: currentKeyTime))
            currentKeyTime += animationTime
        }
        sizeAnimation.values = sizeAnimationValuesArray

        self.indicatorView.layer.add(sizeAnimation, forKey: "Bottom")

但由于某种原因,它不起作用,字面上没有任何反应

1 个答案:

答案 0 :(得分:3)

你实际上并没有使用keyTimes数组。您按时填充了它,但没有将其分配给动画。