我试图保存图像样本缓冲区中的一些元数据以及图像.
我需要:
我试过从数据创建一个UIImage,但是删除了元数据.我已经尝试使用数据中的CIImage来保存元数据,但是我无法将其旋转然后将其保存到文件中.
private func snapPhoto(success: (UIImage, CFMutableDictionary) -> Void, errorMessage: String -> Void) {
guard !self.stillImageOutput.capturingStillImage,
let videoConnection = stillImageOutput.connectionWithMediaType(AVMediaTypeVideo) else { return }
videoConnection.fixVideoOrientation()
stillImageOutput.captureStillImageAsynchronouslyFromConnection(videoConnection) {
(imageDataSampleBuffer, error) -> Void in
guard imageDataSampleBuffer != nil && error == nil else {
errorMessage("Couldn't snap photo")
return
}
let data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer)
let metadata = CMCopyDictionaryOfAttachments(nil, imageDataSampleBuffer, CMAttachmentMode(kCMAttachmentMode_ShouldPropagate))
let metadataMutable = CFDictionaryCreateMutableCopy(nil, 0, metadata)
let utcDate = "\(NSDate())"
let cfUTCDate = CFStringCreateCopy(nil, utcDate)
CFDictionarySetValue(metadataMutable!, unsafeAddressOf(kCGImagePropertyGPSDateStamp), unsafeAddressOf(cfUTCDate)) …Run Code Online (Sandbox Code Playgroud) 从iOS 10开始,我注意到动画布局更改(layoutIfNeeded())不是动画.这是我的UIView扩展,在iOS 9及更低版本上运行良好.
func slideIn(from edgeConstraint: NSLayoutConstraint, withDuration duration: Double = 0.25, finishedAnimating: (() -> Void)? = nil) {
dispatch_async(dispatch_get_main_queue()) {
edgeConstraint.constant = 0
UIView.animateWithDuration(duration,
delay: 0.0,
options: .BeginFromCurrentState,
animations: { self.layoutIfNeeded() },
completion: { didComplete in
finishedAnimating?()
})
}
}
func slideOut(from edgeConstraint: NSLayoutConstraint, withDuration duration: Double = 0.25, finishedAnimating: (() -> Void)? = nil) {
dispatch_async(dispatch_get_main_queue()) {
edgeConstraint.constant = -self.frame.height
UIView.animateWithDuration(duration,
delay: 0.0,
options: .BeginFromCurrentState,
animations: { self.layoutIfNeeded() },
completion: { didComplete in
finishedAnimating?()
})
} …Run Code Online (Sandbox Code Playgroud)