UIImagePickerController 第一次打开很慢,除了双击的时候 [英] UIImagePickerController slow on opening for the first time, except for when you double tap

查看:145
本文介绍了UIImagePickerController 第一次打开很慢,除了双击的时候的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 iOS 9 上使用 swift 得到了这种非常奇怪的行为,其中我有一个 tableViewCell,当点击它拍摄某物时会打开一个 imagePicker,当您第一次点击单元格需要 10 秒钟才能打开选择器,但是当您点击它两次时它会立即打开...

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...

picker的初始化代码如下

The initialisation code for the picker is as follows

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

呈现选择器的代码是presentViewController(certificateImagePicker, animation: 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.

推荐答案

我在第一次尝试展示 UIImagePickerController 时遇到了类似的延迟.在我的情况下,在初始化父 UIViewController 时初始化它有很大帮助,如下所示:

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)
  }
}

这篇关于UIImagePickerController 第一次打开很慢,除了双击的时候的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆