我很久以前在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
我错过了什么吗? 谢谢。