1

我将几个动画链接在一起,并且无法消除连续动画之间的暂停。首先,我尝试在完成块中嵌套 UIView 动画。从那以后,我转向了这个解决方案:

http://xibxor.com/objective-c/uiview-animation-without-nested-hell/

我认为它更具可读性,但我有同样的暂停问题。

4

2 回答 2

1

问题可能是您的动画时间,而不是暂停。默认情况下,动画使用缓入缓出时间。这意味着每个动画从 0 开始,加速到全速,然后减速到停止。然后下一个动画做同样的事情。

如果您想链接一系列动画以创建无缝效果,您可能需要使用线性动画计时。查看UIView类方法animateWithDuration:delay:options:animations:completion:

为 options 参数传入 UIViewAnimationOptionCurveLinear。

于 2013-06-12T14:41:11.570 回答
1

这很快,懒得转换为目标 C。在动画交易块中将动画链接在一起。

斯威夫特 2

UIView.animateKeyframesWithDuration(totalAnimationDuration, delay: 0, options:UIViewKeyframeAnimationOptions.CalculationModeLinear, animations: {

    for (var i = 0; i < wayPoints.count; i++) {
        let nextWayPoint = wayPoints[i]

        UIView.addKeyframeWithRelativeStartTime(CGFloat(i) * relativeDuration, relativeDuration: relativeDuration, animations: {
            token.frame = CGRect(x: nextWayPoint.x + self.inset, y: nextWayPoint.y + self.inset, width: token.frame.size.width, height: token.frame.size.height)
        })


    }


}, completion: { success in


})

斯威夫特 3,4,5

UIView.animateKeyframes(withDuration: totalAnimationDuration, delay: 0, options: UIView.KeyframeAnimationOptions.calculationModeLinear, animations: {

    for i in 0..<wayPoints.count {
        let nextWayPoint = wayPoints[i]

        UIView.addKeyframe(withRelativeStartTime: CGFloat(i) * relativeDuration, relativeDuration: relativeDuration, animations: {
            token.frame = CGRect(x: nextWayPoint.x + self.inset, y: nextWayPoint.y + self.inset, width: token.frame.size.width, height: token.frame.size.height)
        })


    }


}, completion: { success in


})
于 2014-07-04T00:45:22.750 回答