I'm trying to animate the background of my view for several times. For example(of course it's need to be dynamic solution) for 4 seconds, each second it will animate from white to black. what we expect: second:
- white to black to white
- white to black to white
- white to black to white
- white to black to white
I tried using for and even delay(dispatch delay),and it will run it only 1 time and than stop. This is what I tried.
for var index = 0; index < 3; ++index {
UIView.animateWithDuration(0.33333, delay: 0.333333, options: UIViewAnimationOptions.CurveEaseIn, animations: { () -> Void in
println(elapsedTime)
self.view.backgroundColor = UIColor.blackColor()
}) { (completed : (Bool)) -> Void in
UIView.animateWithDuration(0.333333, animations: { () -> Void in
self.view.backgroundColor = UIColor.whiteColor()
})
}
}
Any suggestions on how I can run these commands, wait until they complete and than run them again?