我在使用 swift 的 iOS 9 上遇到了这种非常奇怪的行为,我有一个 tableViewCell
,当点击它拍摄某物时,它会打开一个 imagePicker
,当第一次点击单元格需要大约 10 秒才能打开选择器,但是当你点击它两次时它会立即打开...
picker的初始化代码如下
let certificateImagePicker = UIImagePickerController()
certificateImagePicker.delegate = self
certificateImagePicker.allowsEditing = false
certificateImagePicker.sourceType = .Camera
certificateImagePicker.modalPresentationStyle = .CurrentContext
呈现选择器的代码是presentViewController(certificateImagePicker, animated: false, completion: nil)
我现在不知道它是否相关,但在打开选择器后它会显示此错误消息
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.
最佳答案
我在第一次尝试呈现 UIImagePickerController
时遇到了类似的延迟。在我的案例中,在初始化父 UIViewController
时初始化它很有帮助,如下所示:
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)
}
}
关于ios - UIImagePickerController 第一次打开时速度很慢,双击时除外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38819118/