2014-09-10 21:28:19 +02:00
|
|
|
import UIKit
|
2014-12-08 23:11:24 +01:00
|
|
|
import Gifu
|
2014-09-10 21:28:19 +02:00
|
|
|
|
|
|
|
class ViewController: UIViewController {
|
2016-09-26 23:01:27 +02:00
|
|
|
@IBOutlet weak var imageView: GIFImageView!
|
2018-01-01 21:12:33 +01:00
|
|
|
@IBOutlet weak var imageDataLabel: UILabel!
|
2016-10-01 13:41:22 +02:00
|
|
|
@IBAction func unwindToRootViewController(segue: UIStoryboardSegue) { }
|
|
|
|
|
2016-10-01 13:19:22 +02:00
|
|
|
var currentGIFName: String = "mugen" {
|
|
|
|
didSet {
|
2018-01-01 21:12:33 +01:00
|
|
|
self.animate()
|
2016-10-01 13:19:22 +02:00
|
|
|
}
|
2014-09-10 21:28:19 +02:00
|
|
|
}
|
|
|
|
|
2016-06-19 00:56:52 +02:00
|
|
|
@IBAction func toggleAnimation(_ sender: AnyObject) {
|
2014-11-10 22:57:37 +01:00
|
|
|
if imageView.isAnimatingGIF {
|
|
|
|
imageView.stopAnimatingGIF()
|
2018-01-01 21:12:33 +01:00
|
|
|
print(imageView.gifLoopDuration)
|
2014-09-10 21:28:19 +02:00
|
|
|
} else {
|
2014-11-10 22:57:37 +01:00
|
|
|
imageView.startAnimatingGIF()
|
2018-01-01 21:12:33 +01:00
|
|
|
print(imageView.gifLoopDuration)
|
2015-06-05 11:14:52 -04:00
|
|
|
}
|
|
|
|
}
|
2016-10-01 13:19:22 +02:00
|
|
|
|
|
|
|
@IBAction func swapImage(_ sender: AnyObject) {
|
|
|
|
switch currentGIFName {
|
|
|
|
case "mugen":
|
|
|
|
currentGIFName = "earth"
|
|
|
|
default:
|
|
|
|
currentGIFName = "mugen"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
|
|
imageView.prepareForReuse()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
2018-01-01 21:12:33 +01:00
|
|
|
self.animate()
|
|
|
|
}
|
|
|
|
|
|
|
|
func animate() {
|
|
|
|
imageView.animate(withGIFNamed: currentGIFName) {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
self.imageDataLabel.text = self.currentGIFName.capitalized + " (\(self.imageView.frameCount) frames / \(String(format: "%.2f", self.imageView.gifLoopDuration))s)"
|
|
|
|
}
|
|
|
|
}
|
2016-10-01 13:19:22 +02:00
|
|
|
}
|
2014-09-10 21:28:19 +02:00
|
|
|
}
|