CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position.x"]; animation.fromValue = @0; animation.toValue = @320; animation.duration = 1; [_label.layer addAnimation:animation forKey:@"basic"];
let animation = CABasicAnimation(keyPath: "position.x") animation.fromValue = NSNumber(value: 0.0) animation.toValue = NSNumber(value: 320.0) _label.layer.addAnimation(animation, forKey: "basic")
视图将水平从0移到320。如果要将视图垂直移动,只需像这样替换键路径:
"position.y"