I am trying to use a UIButton to start and stop an animated sequence of images that I have placed into an imageview. I am using swift 3.0
Here is my current code:
import UIKit
class ViewController: UIViewController {
var selectedProgression : Int = 0
var loading_1: UIImage!
var loading_2: UIImage!
var loading_3: UIImage!
var animatedImage: UIImage!
@IBOutlet weak var progressionAnimation: UIImageView!
override func viewDidLoad() {
loading_1 = UIImage(named: "blues-1")
loading_2 = UIImage(named: "blues-2")
loading_3 = UIImage(named: "blues-3")
var images: [UIImage]!
images = [loading_1, loading_2, loading_3]
animatedImage = UIImage.animatedImage(with: images, duration: 3.0)
progressionAnimation.image = animatedImage
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
I've looked and have somewhat of an idea of how to do this, but keep getting stuck while actually implementing the solution into my code :(
From what I've found, I need to create an outlet for the button that measures if it is pressed or not pressed, and connect the button action to startAnimating or stopAnimating when pressed, depending on it's current state.
I found the startAnimating and stopAnimating functions on Apple documentation https://developer.apple.com/documentation/uikit/uiimageview/1621061-startanimating but am unsure of how to actually implement them into the code.
Any help would be GREATLY appreciated. Thank you!