Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在完成之前关闭ImagePicker_Ios_Swift_Swift2_Uiimagepickercontroller - Fatal编程技术网

Ios 在完成之前关闭ImagePicker

Ios 在完成之前关闭ImagePicker,ios,swift,swift2,uiimagepickercontroller,Ios,Swift,Swift2,Uiimagepickercontroller,我在Swift中使用ImagePickerSheetController。我的代码如下所示 controller.addAction(ImagePickerAction(title: NSLocalizedString("Take Photo", comment: "Action Title"), secondaryTitle: NSLocalizedString("Use this photo", comment: "Action Title"), handler: { _ in pr

我在Swift中使用ImagePickerSheetController。我的代码如下所示

 controller.addAction(ImagePickerAction(title: NSLocalizedString("Take Photo", comment: "Action Title"), secondaryTitle: NSLocalizedString("Use this photo", comment: "Action Title"), handler: { _ in

  presentImagePickerController(.Camera)

  }, secondaryHandler:
  { _, numberOfPhotos in

  self.getAssetThumbnail(self.controller.selectedImageAssets.last!)
  self.performImageRecognition(scaledImage)
  }))
我的问题是:在用户选择图像10秒后,ImagePicker get会被取消,这表明应用程序已经冻结。原因是第二种方法
performImageRecognition
使用OCR,因此需要一段时间

我想在功能完成之前关闭控制器,但我如何才能这样做?我可以只添加一个ActivityIndicator,但我更喜欢取消imagePickerController

有人知道怎么做吗


感谢您的帮助,谢谢

由于OCR方法是一项繁重的任务,因此应在拾取完成后调用它。一行接一行不一定保证这一点,因为操作系统是在纳米级执行的。 为什么不实现UIImagePickerController的委托方法?因此,你可以把你的代码放在didFinishPickingMediaWithInfo上,在那里做OCR的事情,也可以自己解雇挑选者。 例如:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
if let pickedImg = info[UIImagePickerControllerOriginalImage] as? UIImage 
{
    // use your pickedImg
}

dismissViewControllerAnimated(true, completion: nil)

// do your OCR stuff here...}
不要忘记
picker.delegate=self


祝你好运

事实上,我试过使用didFinishPickingMediaWithInfo。因为我使用的自定义UIImagePicker没有调用此方法,所以这是无用的。。谢谢你的帮助!