小编Sea*_*159的帖子

Swift:自定义相机使用图像保存已修改的元数据

我试图保存图像样本缓冲区中的一些元数据以及图像.

我需要:

  • 将图像旋转到元数据的方向
  • 从元数据中删除方向
  • 保存所采用的日期到元数据
  • 将带有元数据的图像保存到文档目录中

我试过从数据创建一个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 swift swift2

9
推荐指数
1
解决办法
5001
查看次数

iOS 10中的动画错误

从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)

animation constraints ios swift ios10

1
推荐指数
1
解决办法
2567
查看次数

标签 统计

ios ×2

swift ×2

animation ×1

constraints ×1

ios10 ×1

swift2 ×1