我想转换捕获的视频并将其转换成Gif,但我在保存转换后的Gif并将其保存到UIImage对象时遇到了问题。 Ultimatley,我试图用这个对象在UIImageView上显示gif。另外,请注意,我使用NSGIF将我的视频转换为GIF。这是我的代码:保存gif到UIImage
@IBOutlet weak var tempImageView3: UIImageView!
@IBAction func capture(sender: AnyObject) {
if !isRecording {
isRecording = true
UIView.animateWithDuration(0.5, delay: 0.0, options: [.Repeat, .Autoreverse, .AllowUserInteraction], animations: {() ->() in
self.cameraButton.transform = CGAffineTransformMakeScale(0.5, 0.5)
}, completion: nil)
let outputPath = NSTemporaryDirectory() + "output.mov"
let outputFileURL = NSURL(fileURLWithPath: outputPath)
let gifURL: NSURL
NSGIF.createGIFfromURL(outputFileURL, withFrameCount: 16, delayTime: Float(0.2), loopCount: 0, completion: { (gifURL) -> Void in
print("output saved \(gifURL)")
})
videoFileOutput?.startRecordingToOutputFileURL(outputFileURL, recordingDelegate: self)
} else {
isRecording = false
UIView.animateWithDuration(0.5, delay: 1.0, options: [], animations: {() ->() in
self.cameraButton.transform = CGAffineTransformMakeScale(1.0, 1.0)
}, completion: nil)
cameraButton.layer.removeAllAnimations()
videoFileOutput?.stopRecording()
}
}