我在看這個分支在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呢? –
關於正確的聲音,介紹數據爲零且錯誤不是的情況。 –