0
我有一个特定的动画效果的四个funcs UIImageView
,我已经在一个数组中设置了这些funcs。当我点击一个按钮时,我想让动画一个接一个地发生,但它们都发生在同一时间。Swift:试图让动画一个接一个地发生
我该怎么做才能让动画完成后动画开始动画?
CODE:
override func viewDidLoad() {
super.viewDidLoad()
self.initAdMobBanner()
funcArray = [self.animatePattern1, self.animatePattern2, self.animatePattern3, self.animatePattern4]
createArrays()
score = 0
scoreLabel.text = "\(score)"
highScore = NSUserDefaults.standardUserDefaults().integerForKey("HighScore")
tapButton.hidden = false
goButton.hidden = true
}
@IBAction func tapButton(sender: AnyObject) {
self.tapButton.hidden = true
self.main.shuffleInPlace()
print(self.main)
UIView.animateWithDuration(1, delay: NSTimeInterval(1.0), options: .Autoreverse, animations: {
self.funcArray[self.main[0] - 1]()
}) { _ in
UIView.animateWithDuration(1, delay: NSTimeInterval(2.0), options: .Autoreverse, animations: {
self.funcArray[self.main[1] - 1]()
}, completion: { _ in
UIView.animateWithDuration(1, delay: NSTimeInterval(3.0), options: .Autoreverse, animations: {
self.funcArray[self.main[2] - 1]()
}, completion: { _ in
UIView.animateWithDuration(1, delay: NSTimeInterval(4.0), options: .Autoreverse, animations: {
self.funcArray[self.main[3] - 1]()
}, completion: { _ in
self.goButton.hidden = false
})
})
})
}
}
func createArrays() {
self.p1.backgroundColor = self.colors[1]
self.p2.backgroundColor = self.colors[2]
self.p3.backgroundColor = self.colors[3]
self.p4.backgroundColor = self.colors[4]
}
func animatePattern1() {
UIView.animateWithDuration(0.3, animations: {() -> Void in
self.p1.transform = CGAffineTransformMakeScale(0.9, 0.9)
}) { (finished: Bool) -> Void in
UIView.animateWithDuration(0.3, animations: {() -> Void in
self.p1.transform = CGAffineTransformIdentity
})}
}
func animatePattern2() {
UIView.animateWithDuration(0.3, animations: {() -> Void in
self.p2.transform = CGAffineTransformMakeScale(0.9, 0.9)
}) { (finished: Bool) -> Void in
UIView.animateWithDuration(0.3, animations: {() -> Void in
self.p2.transform = CGAffineTransformIdentity
})}
}
func animatePattern3() {
UIView.animateWithDuration(0.3, animations: {() -> Void in
self.p3.transform = CGAffineTransformMakeScale(0.9, 0.9)
}) { (finished: Bool) -> Void in
UIView.animateWithDuration(0.3, animations: {() -> Void in
self.p3.transform = CGAffineTransformIdentity
})}
}
func animatePattern4() {
UIView.animateWithDuration(0.3, animations: {() -> Void in
self.p4.transform = CGAffineTransformMakeScale(0.9, 0.9)
}) { (finished: Bool) -> Void in
UIView.animateWithDuration(0.3, animations: {() -> Void in
self.p4.transform = CGAffineTransformIdentity
})}
}