如何创建CAAnimationGroup?

时间:2016-12-16 02:33:33

标签: swift xcode core-animation caanimation

我有两个动画,我想创建一个群组动画,这可能吗? 这是我的代码:

这是我的两个动画

    let spring = CASpringAnimation(keyPath: "position.x")
    spring.damping = 6
    spring.stiffness = 28.6
    spring.mass = 0.5
    spring.toValue = toValue
    spring.duration = duration
    spring.beginTime = CACurrentMediaTime() +  2
    spring.isRemovedOnCompletion = false
    spring.fillMode = kCAFillModeForwards

    let animationPosition = CABasicAnimation(keyPath: "position.x")
    animationPosition.duration = duration
    animationPosition.toValue  =  toValue
    animationPosition.beginTime = CACurrentMediaTime() + 3
    animationPosition.isRemovedOnCompletion = false
    animationPosition.fillMode = kCAFillModeForwards

我尝试创建这样的组,但不起作用

    let spring = CASpringAnimation(keyPath: "position.x")
    spring.damping = 6
    spring.stiffness = 28.6
    spring.mass = 0.5
    spring.toValue = toValue
    spring.duration = duration1
    spring.beginTime = 0

    let animationPosition = CABasicAnimation(keyPath: "position.x")
    animationPosition.duration = duration2
    animationPosition.toValue  =  toValue
    animationPosition.beginTime = 3

    let group = CAAnimationGroup.init()
    group.duration = duration1 + duration2
    group.repeatCount = 1
    group.beginTime = CACurrentMediaTime() + 2
    group.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    group.isRemovedOnCompletion = false
    group.fillMode = kCAFillModeForwards
    group.animations = [spring, animationPosition]

0 个答案:

没有答案