UIImagePickerController 第一次打开很慢,除了双击的时候

编程入门 行业动态 更新时间:2024-10-28 17:21:21
本文介绍了UIImagePickerController 第一次打开很慢,除了双击的时候的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 03:56:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1184035.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:双击   很慢   UIImagePickerController

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!