在Swift中创build一个animationgif的问题

我试图从Swift中的4个UIImage元素的数组中创build一个animationGIF,但目前它只保存第一帧。

 let url = NSURL(fileURLWithPath: photosDirectory)?.URLByAppendingPathComponent(filename()) if let url = url { let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]] let gifProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: 0.125]] let destination = CGImageDestinationCreateWithURL(url, kUTTypeGIF, photos.count, nil) CGImageDestinationSetProperties(destination, fileProperties) for photo in photos { CGImageDestinationAddImage(destination, photo.CGImage, gifProperties) } return CGImageDestinationFinalize(destination) } else { return false } 

photosUIImages filename()的数组只是返回像20150805.gifstring

它返回true,但只有第一帧在gif中

kCGImagePropertyGIFDelayTime应该是float而不是double。

尝试设置0.125f而不是0.125