问题
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