UIImagePickerController slow on opening for the first time, except for when you double tap

匆匆过客 提交于 2019-12-23 01:01:12

问题


I'm getting this really weird behaviour on iOS 9 with swift where I have a tableViewCell that opens an imagePicker when tapped on to take a picture of something, when you tap the cell for the first time it takes like 10 seconds to open the picker, but when you tap it twice it immediately opens...

The initialisation code for the picker is as follows

let certificateImagePicker = UIImagePickerController()
certificateImagePicker.delegate = self
certificateImagePicker.allowsEditing = false
certificateImagePicker.sourceType = .Camera
certificateImagePicker.modalPresentationStyle = .CurrentContext

The code for presenting the picker is presentViewController(certificateImagePicker, animated: false, completion: nil)

I do not now if it related but after opening the picker it show this error message

Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.


回答1:


I experienced a similar delay in presenting a UIImagePickerController on the first try. What helped a lot in my case was initialising it when also initializing the parent UIViewController, like so:

class ExampleViewController: UIViewController, UIImagePickerControllerDelegate {
  let imagePicker = UIImagePickerController()

  func presentImagePicker() {
    imagePicker.delegate = self
    imagePicker.allowsEditing = false
    imagePicker.sourceType = .camera
    imagePicker.modalPresentationStyle = .currentContext
    self.present(imagePicker, animated: false, completion: nil)
  }
}


来源:https://stackoverflow.com/questions/38819118/uiimagepickercontroller-slow-on-opening-for-the-first-time-except-for-when-you

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!