Gifu/Demo/Source/ViewController.swift

50 lines
1.2 KiB
Swift
Raw Normal View History

2014-09-10 19:28:19 +00:00
import UIKit
2014-12-08 22:11:24 +00:00
import Gifu
2014-09-10 19:28:19 +00:00
class ViewController: UIViewController {
@IBOutlet weak var imageView: GIFImageView!
@IBOutlet weak var imageDataLabel: UILabel!
2016-10-01 11:41:22 +00:00
@IBAction func unwindToRootViewController(segue: UIStoryboardSegue) { }
2016-10-01 11:19:22 +00:00
var currentGIFName: String = "mugen" {
didSet {
self.animate()
2016-10-01 11:19:22 +00:00
}
2014-09-10 19:28:19 +00:00
}
@IBAction func toggleAnimation(_ sender: AnyObject) {
if imageView.isAnimatingGIF {
imageView.stopAnimatingGIF()
print(imageView.gifLoopDuration)
2014-09-10 19:28:19 +00:00
} else {
imageView.startAnimatingGIF()
print(imageView.gifLoopDuration)
2015-06-05 15:14:52 +00:00
}
}
2016-10-01 11:19:22 +00: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) {
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 11:19:22 +00:00
}
2014-09-10 19:28:19 +00:00
}