我在看这个分支在GitHub上:这个Swift函数创建的对象在哪里?
https://gist.github.com/westerlund/eae8ec71cdac88be7c3a
这是函数,用于斯威夫特创建UIImages一个GIF:
func createGIF(with images: [UIImage], loopCount: Int = 0, frameDelay: Double, callback: (data: NSData?, error: NSError?) ->()) {
let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: loopCount]]
let frameProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: frameDelay]]
let documentsDirectory = NSTemporaryDirectory()
let url = NSURL(fileURLWithPath: documentsDirectory)?.URLByAppendingPathComponent("animated.gif")
if let url = url {
let destination = CGImageDestinationCreateWithURL(url, kUTTypeGIF, UInt(images.count), nil)
CGImageDestinationSetProperties(destination, fileProperties)
for i in 0..<images.count {
CGImageDestinationAddImage(destination, images[i].CGImage, frameProperties)
}
if CGImageDestinationFinalize(destination) {
callback(data: NSData(contentsOfURL: url), error: nil)
} else {
callback(data: nil, error: NSError())
}
} else {
callback(data: nil, error: NSError())
}
}
我不知道我的理解是什么继续。该函数不应该返回一个要使用的对象吗?创建的GIF去哪里?是否有可能在我的代码的其他部分使用它,例如将它放在UIImageView或UIImage中?
谢谢
进入回调?这行'回调(数据:NSData(contentsOfURL:url),错误:无)' –
那么我应该使用NSData创建一个UIImage呢? –
关于正确的声音,介绍数据为零且错误不是的情况。 –