how to iterate through functions with button press in Swift
Your code should like this :
// You can define this variable globally...
var counter = 0
@IBAction func nextAnimation(_ sender: UIButton) {
if (counter == 0) {
funcAnimation1()
// Increase counter count by 1 and you can add this line to completion of animation.
// You can also disable your button interaction until your animation gets complete and that way you can handle your UI
count += 1
}
else if (counter == 1) {
funcAnimation2()
// Increase counter count by 1 and you can add this line to completion of animation.
count += 1
}
else if (counter == 2) {
funcAnimation3()
// set your counter to 0 again to loop through your animation.
counter = 0
}
}
Your Back Action should look like this:
@IBAction func backAnimation(_ sender: UIButton) {
if (counter == 0) {
funcAnimation1()
// set your counter to 2 again to loop through your animation.
count = 2
}
else if (counter == 1) {
funcAnimation2()
// decrease counter count by 1 and you can add this line to completion of animation.
// You can also disable your button interaction until your animation gets complete and that way you can handle your UI
count -= 1
}
else if (counter == 2) {
funcAnimation3()
// decrease counter count by 1 and you can add this line to completion of animation.
count -= 1
}
}