ios - UIImagePickerController 第一次打开时速度很慢,双击时除外

标签 ios swift uiimagepickercontroller

我在使用 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/

相关文章:

iphone - 从相机捕获图像后,应用程序在后台时收到通知

ios - 如何将图像保存到 Parse 的主要用户类?

ios - 如何异步将获取的json数据逐段更新到tableView

ios - 将参数从函数传递给 prepareForSegue

json - 如何使用按钮或拉动刷新来刷新 TableView 和 JSON 数据?

swift - 当 App 显示 NSAlert 时保持 Cocoa 窗口最小化

swift - 为什么 Xcode 不突出显示所有错误?

javascript - 以编程方式启动 UIWebView 键盘

iphone - 仅当在 iphone image-Picker 中完成捕获时单击捕获按钮时如何执行操作

ios - 如何响应 UIImagePickerController 生成的 UIAlertView