:このSwift関数で作成されたオブジェクトはどこに移動しますか?私はGitHubの上で、この支店で探しています
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)、エラー:nil)' –
そこから、私はNSDataを使ってUIImageを作成する必要がありますか? –
右のように聞こえますが、データがゼロでエラーがない場合に気をつけてください。 –