swift UIView animateWithDuration重复和自动反向

我是新手,这是我的第一个问题….我想缩小一个持续2秒的球,然后增长5秒。 我的问题是第二个持续时间被忽略(球收缩2秒,并增长2秒)。 我希望有一个人可以帮助我。

这是我的尝试:

let ball = UIView() ball.frame = CGRectMake(50, 50, 50, 50) ball.backgroundColor = UIColor.blueColor() ball.layer.cornerRadius=25 relaxContainer.addSubview(ball) UIView.animateWithDuration(2.0, delay:0, options: [.Repeat, .Autoreverse], animations: { ball.frame = CGRectMake(50, 50, 20, 20) }, completion: { finished in UIView.animateWithDuration(5.0, animations: { ball.frame = CGRectMake(50, 50, 50, 50) }) }) 

我的答案感谢Matt的帮助(持续时间,原始问题的variables被改变):

  let duration = 6.0 let delay = 0.0 UIView.animateKeyframesWithDuration(duration, delay: delay, options: [.Repeat], animations: { UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 1/3, animations: { ball.frame = CGRectMake(screenWidth/8*3, screenHeight/8*3, screenWidth/4, screenWidth/4) }) UIView.addKeyframeWithRelativeStartTime(1/3, relativeDuration: 2/3, animations: { ball.frame = CGRectMake(screenWidth/4, screenHeight/4, screenWidth/2, screenWidth/2) }) }, completion: nil )