“zPosition”CABasicAnimation不起作用

时间:2017-08-20 17:12:56

标签: ios swift animation core-animation

我很久以前在Objective C中使用了z轴的动画:

    CABasicAnimation *positionAnimation;

    positionAnimation=[CABasicAnimation animationWithKeyPath:@"zPosition"];
    positionAnimation.fromValue=[NSNumber numberWithFloat:frandom(800, 400)];
    positionAnimation.toValue=[NSNumber numberWithFloat:frandom(-300, -100)];
    positionAnimation.duration=duration;
    positionAnimation.repeatCount = HUGE_VALF;
    positionAnimation.removedOnCompletion = NO;

但它不再适用于swift 3,该层根本不会移动。

        let positionAnimation = CABasicAnimation(keyPath: "zPosition")
        positionAnimation.fromValue = NSNumber(value: Float.random(from: 800, 400))
        positionAnimation.toValue = NSNumber(value: Float.random(from: -300, -100))
        positionAnimation.duration = duration
        positionAnimation.repeatCount = 400
        positionAnimation.isRemovedOnCompletion = false

我错过了什么吗? 谢谢。

0 个答案:

没有答案