【问题标题】:Capturing gyroscope data at exact moment of photo capture在照片捕获的确切时刻捕获陀螺仪数据
【发布时间】:2017-03-17 21:32:33
【问题描述】:

我正在创建一个应用程序,该应用程序将捕捉照片并在照片捕捉时根据陀螺仪数据重新调整它的方向。

我已经创建了从手机中捕获陀螺仪数据的函数:

startUpdates()

并停止在以下位置捕获数据:

stopUpdates()

我尝试将它添加到 UIImagePickerController 中:

   if UIImagePickerController.isSourceTypeAvailable(.camera) {
        guard ptInitials.text != "" else {
            missingIdentifier(text: "Please add an identifier prior to taking a photo")
            return}
        startUpdates()  
        imagePicker =  UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.allowsEditing = false
        imagePicker.sourceType = UIImagePickerControllerSourceType.camera
        imagePicker.cameraCaptureMode = .photo
        imagePicker.modalPresentationStyle = .fullScreen
        present(imagePicker,
                animated: true,
            completion: nil)

    }

这会在图像捕获过程开始时启动陀螺仪捕获。

我让它将陀螺仪数据传递给一个可选的 double,livePhotoAxis: Double?,同时它在“startUpdates()”函数中测量这个。

我试图让它在拍照后“停止”捕获数据,以便将最后一个已知的陀螺仪数据保存在我的变量中并能够传递给其他函数;

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    stopUpdates()
    let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
    saveImageToDocuments(image: chosenImage, fileNameWithExtension: "image.jpg")
    dismiss(animated: true, completion: nil

    )

}

但是,问题在于 stopUpdates() 方法直到用户“确认”他们喜欢他们拍摄的照片(而不是重新拍摄)之后才被调用。

根据我的阅读,有一个带有 uiImagePickerControllerUserDidCaptureItem 的私有 API,可以捕获拍摄照片的确切时刻。我可以使用 NSNotification 来尝试找到它,并在实际拍摄照片后调用 StopUpdates()。

这是一个私有 API 是否正确?我可以用它来捕捉这一刻,否则我的应用会被拒绝吗?

同样,有没有更好的方法可以在拍摄照片的确切时刻关闭我的陀螺仪更新?

谢谢!

【问题讨论】:

    标签: ios swift swift3


    【解决方案1】:

    我添加了此代码并解决了问题,但我仍然不知道这是否是私有 API,是否允许在应用商店中使用?或者是否有更好的方法来实现这一点?

            NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "_UIImagePickerControllerUserDidCaptureItem"), object:nil, queue:nil, using: { note in
                self.stopUpdates()
            })
    

    更新:这不会触发照片捕捉的确切时刻。当照片“锁定”时它会触发。在按下拍照按钮和照片锁定到位之间有几秒钟 (2ish)。因此,如果您在此期间移动手机,陀螺仪数据将不准确。

    关于如何改进这一点有什么想法吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多