Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 卡巴斯基化自动翻转速度提高一倍_Ios_Swift_Animation_Core Animation_Cabasicanimation - Fatal编程技术网

Ios 卡巴斯基化自动翻转速度提高一倍

Ios 卡巴斯基化自动翻转速度提高一倍,ios,swift,animation,core-animation,cabasicanimation,Ios,Swift,Animation,Core Animation,Cabasicanimation,我使用此代码添加带有自动翻转的脉冲圆: let scaleAnimation = CABasicAnimation(keyPath: "transform.scale") scaleAnimation.duration = 6 scaleAnimation.repeatCount = 200 scaleAnimation.autoreverses = true scaleAnimation.fromValue = 0.1 scaleAnimation.toValue = 0.8

我使用此代码添加带有自动翻转的脉冲圆:

let scaleAnimation = CABasicAnimation(keyPath: "transform.scale")        
scaleAnimation.duration = 6
scaleAnimation.repeatCount = 200
scaleAnimation.autoreverses = true
scaleAnimation.fromValue = 0.1
scaleAnimation.toValue = 0.8
scaleAnimation.timingFunction = CAMediaTimingFunction(controlPoints: 0.42, 0.0, 0.58, 1.0)
animationView.layer.add(scaleAnimation, forKey: "scale")
我想在这里做的是:

2x速度运行动画
fromValue=0.1
toValue=0.8
, 然后以
1x速度向后设置动画
从value=0.8
到value=0.1


有没有一个简单的方法来实现这一点

有两种方法可以做到这一点:

(您的最佳选择):

专为使用多个关键帧设置单个
关键路径的动画而设计,每个间隔上都有自定义的时间功能。正是你需要的

let scaleAnimation = CAKeyframeAnimation(keyPath: "transform.scale")
scaleAnimation.duration = 18 // 6 seconds for the first part, 12 for the second
scaleAnimation.repeatCount = 200
scaleAnimation.values = [0.1, 0.8, 0.1] // make sure first and last values are equal in order to get seamless animation
scaleAnimation.keyTimes = [0, 0.333, 1] // keyframes scaled to [0; 1] interval
scaleAnimation.timingFunctions = [
    CAMediaTimingFunction(controlPoints: 0.42, 0.0, 0.58, 1.0), //first interval
    CAMediaTimingFunction(controlPoints: 0.58, 0.0, 0.42, 1.0)  //second interval (reversed)
]
layer.add(scaleAnimation, forKey: nil)
(一种变通方法)

设计用于为单个层分组动画(可能使用不同的
keyPath
s)

let scaleUpAnimation = CAKeyframeAnimation(keyPath: "transform.scale")
//setup first animation as you did

let scaleDownAnimation = CAKeyframeAnimation(keyPath: "transform.scale")
//setup second animation

let groupAnimation = CAAnimationGroup()
groupAnimation.animations = [scaleUpAnimation, scaleDownAnimation]
//setup group if needed
layer.add(groupAnimation, forKey: nil)

您是否尝试过
cakeyLeanimation
?谢谢!帮了我很多忙。我用
CAAnimationGroup
来解决我的问题。顺便问一下,有没有办法在每次动画开始时获得回调?我尝试使用
CAAnimationDelegate
,但它只为组本身提供启动/停止回调,而不提供组内的动画。