Trying to get playButton to be able to start and stop an animation by using an if/else statement. The button text will change to Stop but will not stop the animation. Not knowing for sure I’ve tried changing the State Config in the Attributes inspector, with no luck. Im sure its super easy, any help would be awesome. Thank you Herm
import UIKit
import AVFoundation
class ViewController: UIViewController {
@IBOutlet weak var arnoldImageView: UIImageView!
@IBOutlet weak var playButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func playButtonPressed(_ sender: Any) {
arnoldImageView.animationImages = [UIImage(named: "th1")!,
UIImage(named: "th-2")!,
UIImage(named: "th-3")!,
UIImage(named: "th-4")!]
arnoldImageView.animationDuration = 2.0
if arnoldImageView.isAnimating
{
//stop button is pressed
arnoldImageView.stopAnimating()
playButton.setTitle("START", for: UIControlState.normal)
playButton.tintColor = UIColor.green
}else{
//start button is pressed
arnoldImageView.startAnimating()
playButton.setTitle("STOP", for: UIControlState.normal)
playButton.tintColor = UIColor.red
}
}
}