【发布时间】:2016-09-12 23:55:42
【问题描述】:
我正在尝试转换捕获的视频并将其转换为 Gif,但在保存转换后的 Gif 并将其保存到 UIImage 对象时遇到问题。最后,我正在尝试使用此对象在 UIImageView 上显示 gif。另外,请注意我正在使用 NSGIF 将我的视频转换为 Gif。这是我的代码:
@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()
}
}
【问题讨论】: