动画在Swift中完成时调用函数

时间:2015-02-04 13:12:59

标签: swift animation

我有一个以应用程序开头的动画。当这个动画结束时,我需要调用另一个函数,但是我找不到执行它的过程。

这是我的动画代码:

func bettyAnimation(){

var betty: UIImageView = UIImageView()

var bettyImageList: [UIImage] = []

for i in 1...77{
    let imageName = "pantalla_02_betty_\(i).png"
    bettyImageList += [UIImage(named: imageName)!]
}

self.view.addSubview(betty)
betty.animationRepeatCount=1
betty.animationImages = bettyImageList
betty.animationDuration = 6.0

betty.startAnimating()

}

1 个答案:

答案 0 :(得分:3)

您需要将代码放在completion块中。

UIView.animateWithDuration(
  // duration
  1.0,
  // delay
  delay: 0.0, 
  options: nil, 
  animations: {

   // put animation code here

  }, completion: {finished in

   // the code you put here will be executed when your animation finishes, therefore
   // call your function here 
  }
)