将Swift CAKeyframeAnimation转换为CSS

时间:2019-02-14 22:45:46

标签: css swift

我在CAGradientLayer上有一个CAKeyframeAnimation,我想将其转换为渐变上的CSS关键帧动画。我已经复制了渐变,我只需要关键帧动画本身的帮助。

到目前为止,我在CSS中拥有什么:

background: linear-gradient(45deg, #e30613, #312782, #00a19a);

Swift动画:

let duration:CFTimeInterval = 30

let animSt = CAKeyframeAnimation(keyPath: "startPoint")
animSt.values = [CGPoint(x: 0, y: 1),
                 CGPoint(x: 1, y: 1),
                 CGPoint(x: 1, y: 1),
                 CGPoint(x: 1, y: -1),
                 CGPoint(x: 1, y: -1),
                 CGPoint(x: -1, y: -1),
                 CGPoint(x: -1, y: -1),
                 CGPoint(x: -1, y: 1),
                 CGPoint(x: 0, y: 1),
                 CGPoint(x: 0, y: 1)]
animSt.duration = duration

let animEd = CAKeyframeAnimation(keyPath: "endPoint")
animEd.values = [CGPoint(x: 1, y: 0),
                 CGPoint(x: 1, y: 0),
                 CGPoint(x: -1, y: 0),
                 CGPoint(x: -1, y: 1),
                 CGPoint(x: 1, y: 1),
                 CGPoint(x: 1, y: 1),
                 CGPoint(x: 1, y: -1),
                 CGPoint(x: 1, y: -1),
                 CGPoint(x: 1, y: -1),
                 CGPoint(x: 1, y: 0)]
animEd.duration = duration

let group = CAAnimationGroup()
group.animations = [animSt, animEd]
group.duration = duration
group.repeatCount = .infinity

0 个答案:

没有答案