【发布时间】: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 是否正确?我可以用它来捕捉这一刻,否则我的应用会被拒绝吗?
同样,有没有更好的方法可以在拍摄照片的确切时刻关闭我的陀螺仪更新?
谢谢!
【问题讨论】: