diff --git a/Demo/Demo-iOS/ViewController.swift b/Demo/Demo-iOS/ViewController.swift index 1240e34..5eb0978 100755 --- a/Demo/Demo-iOS/ViewController.swift +++ b/Demo/Demo-iOS/ViewController.swift @@ -23,11 +23,10 @@ class ViewController: UIViewController { } @IBAction func swapImage(_ sender: AnyObject) { - switch currentGIFName { - case "mugen": - currentGIFName = "earth" - default: - currentGIFName = "mugen" + let gifs = ["mugen", "earth", "nailed"] + if let index = gifs.firstIndex(of: currentGIFName) { + let nextIndex = (index + 1) % gifs.count + currentGIFName = gifs[nextIndex] } } @@ -40,7 +39,7 @@ class ViewController: UIViewController { } func animate() { - imageView.animate(withGIFNamed: currentGIFName, animationBlock: { + imageView.animate(withGIFNamed: currentGIFName, preparationBlock: { DispatchQueue.main.async { self.imageDataLabel.text = self.currentGIFName.capitalized + " (\(self.imageView.frameCount) frames / \(String(format: "%.2f", self.imageView.gifLoopDuration))s)" } diff --git a/Demo/Demo.xcodeproj/project.pbxproj b/Demo/Demo.xcodeproj/project.pbxproj index cedf5c4..df8eccf 100755 --- a/Demo/Demo.xcodeproj/project.pbxproj +++ b/Demo/Demo.xcodeproj/project.pbxproj @@ -23,6 +23,8 @@ 9D98823F19BC69CA00B790C6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D98823E19BC69CA00B790C6 /* ViewController.swift */; }; 9D98824419BC69CA00B790C6 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9D98824319BC69CA00B790C6 /* Images.xcassets */; }; 9D98825A19BC69F600B790C6 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9D98825919BC69F600B790C6 /* Main.storyboard */; }; + A5D726E828B53C0800821347 /* earth.gif in Resources */ = {isa = PBXBuildFile; fileRef = A5D726E728B53C0800821347 /* earth.gif */; }; + A5D726EC28B5599A00821347 /* nailed.gif in Resources */ = {isa = PBXBuildFile; fileRef = A5D726EB28B5599A00821347 /* nailed.gif */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -59,6 +61,8 @@ 9D98823E19BC69CA00B790C6 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 9D98824319BC69CA00B790C6 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 9D98825919BC69F600B790C6 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; + A5D726E728B53C0800821347 /* earth.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; name = earth.gif; path = ../Tests/Images/earth.gif; sourceTree = SOURCE_ROOT; }; + A5D726EB28B5599A00821347 /* nailed.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; name = nailed.gif; path = ../Tests/Images/nailed.gif; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -149,7 +153,9 @@ 9D98823A19BC69CA00B790C6 /* Supporting Files */ = { isa = PBXGroup; children = ( + A5D726E728B53C0800821347 /* earth.gif */, 002A1BFB1D1624D0005ABBD0 /* mugen.gif */, + A5D726EB28B5599A00821347 /* nailed.gif */, ); path = "Supporting Files"; sourceTree = ""; @@ -250,6 +256,8 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + A5D726E828B53C0800821347 /* earth.gif in Resources */, + A5D726EC28B5599A00821347 /* nailed.gif in Resources */, 9D98824419BC69CA00B790C6 /* Images.xcassets in Resources */, 002A1BFC1D1624D0005ABBD0 /* mugen.gif in Resources */, 0032FE841FFA693500444203 /* LaunchScreen.storyboard in Resources */, diff --git a/Gifu.xcodeproj/project.pbxproj b/Gifu.xcodeproj/project.pbxproj index 4488d92..1303118 100644 --- a/Gifu.xcodeproj/project.pbxproj +++ b/Gifu.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ 00B8C7961A3650EE00C188E7 /* Gifu.h in Headers */ = {isa = PBXBuildFile; fileRef = 00B8C7951A3650EE00C188E7 /* Gifu.h */; settings = {ATTRIBUTES = (Public, ); }; }; 00BF42CC1D99A1DC00C6F28D /* GIFAnimatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00BF42CB1D99A1DC00C6F28D /* GIFAnimatable.swift */; }; 00DD26EE1DA9643800A0F683 /* UIImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00DD26ED1DA9643800A0F683 /* UIImageView.swift */; }; + A5D726EA28B53D6400821347 /* earth.gif in Resources */ = {isa = PBXBuildFile; fileRef = A5D726E928B53D6400821347 /* earth.gif */; }; EAF49C7F1A3A4DE000B395DF /* UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF49C7E1A3A4DE000B395DF /* UIImage.swift */; }; EAF49CB11A3B6EEB00B395DF /* AnimatedFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF49CB01A3B6EEB00B395DF /* AnimatedFrame.swift */; }; /* End PBXBuildFile section */ @@ -52,6 +53,7 @@ 00BF42CB1D99A1DC00C6F28D /* GIFAnimatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GIFAnimatable.swift; sourceTree = ""; }; 00C50CFB2392BA9900CBE23C /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 00DD26ED1DA9643800A0F683 /* UIImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImageView.swift; sourceTree = ""; }; + A5D726E928B53D6400821347 /* earth.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = earth.gif; sourceTree = ""; }; EAF49C7E1A3A4DE000B395DF /* UIImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImage.swift; sourceTree = ""; }; EAF49CB01A3B6EEB00B395DF /* AnimatedFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnimatedFrame.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -88,6 +90,7 @@ 0036ABBA1BBD1D1700C6CC3D /* Images */ = { isa = PBXGroup; children = ( + A5D726E928B53D6400821347 /* earth.gif */, 0036ABB61BBD1D0B00C6CC3D /* mugen.gif */, 0036ABB81BBD1D1400C6CC3D /* nailed.gif */, ); @@ -271,6 +274,7 @@ files = ( 0036ABB71BBD1D0B00C6CC3D /* mugen.gif in Resources */, 0036ABB91BBD1D1400C6CC3D /* nailed.gif in Resources */, + A5D726EA28B53D6400821347 /* earth.gif in Resources */, ); runOnlyForDeploymentPostprocessing = 0; };