Using Rob Mayoff's answer to create GIF, I've adapted his code to the following in Swift.
let kFrameCount:Int = 6
let frames:NSNumber = NSNumber(float: 20000.0) //No matter what number I place here...GIF runs at same speed
let fileProperties = [kCGImagePropertyGIFLoopCount as String: 0]
let frameProperties = [kCGImagePropertyGIFDelayTime as String: frames]
let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as! NSURL
let fileURL = documentsUrl.URLByAppendingPathComponent("animated.gif")
var destination: CGImageDestination = CGImageDestinationCreateWithURL(fileURL, kUTTypeGIF, kFrameCount, nil)
var destination2: Void = CGImageDestinationSetProperties(destination, fileProperties)
for i in 0..<kFrameCount {
CGImageDestinationAddImage(destination, imagessss[i].CGImage, frameProperties)
}
if (!CGImageDestinationFinalize(destination)) {
println("fail")
}
println(fileURL)
let activityVC: UIActivityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)
self.presentViewController(activityVC, animated: true, completion: nil)
This creates the GIF. But no matter what amount I place as the float
, 20000.0 or 0.01, the GIF runs at the same DelayTime. Also if I change the value in fileProperties
from 0 to any other number, the GIF still does a continuous loop.
I feel the error lies in the line
var destination2: Void = CGImageDestinationSetProperties(destination, fileProperties)
or my declaration of fileProperties
and frameProperties
Does Anyone know why my fileProperties
and frameProperties
are not effecting the GIF?
P.S. I can effectively slowdown the gif by increasing the frames and lacing the imagessss
array with duplicate images, But this isn't ideal.