点击时从当前状态继续动画

时间:2018-08-24 15:34:16

标签: swift animation

我有一个旋转的动画,我希望该动画从轻按时的状态继续。为此,我尝试了以下代码:

if let presentation = plus.presentation() {
    object.frame = presentation.frame
    object.setValue(presentation.value(forKeyPath: animation.keyPath!), forKey: animation.keyPath!) // doesn't do much it seems
    object.transform = presentation.transform
}

但是当再次轻按该对象时,它似乎从另一个锚点开始旋转:

normal(正常)

tapped(在点击时)


func rotateObject() {
    let animation = CABasicAnimation(keyPath: "transform.rotation")

    animation.toValue = CGFloat.pi * 2

    let curve = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)

    animation.timingFunction = curve
    animation.duration = 1.5

    if let presentation = plus.presentation() {
        object.frame = presentation.frame
        object.setValue(presentation.value(forKeyPath: animation.keyPath!), forKey: animation.keyPath!)
        object.transform = presentation.transform
    }

    object.removeAllAnimations()

    object.add(animation, forKey: animation.keyPath)
}

点击时,我应该使用什么来获取旋转状态?

0 个答案:

没有答案