Swift 5 imagePickerController 不显示相机图像

发布于 2025-01-18 19:27:04 字数 1152 浏览 2 评论 0原文

相机显示问题

大家好,

我是 Swift 新手,所以请耐心等待我尝试解释我的问题。

我正在 XCode 13 中编写一个应用程序,该应用程序应该拍摄照片并将其显示在名为“ImageResult”的 UIImageView 中。

以下两个函数执行所需的任务:

// Calls Camera (Works)

@objc private func TakePhoto(_ sender: Any) {

let picker = UIImagePickerController( )

picker.sourceType = .camera

picker.allowsEditing = true

picker.delegate = self

present(picker, 动画:正确) }

// 显示来自相机的图像(不起作用)

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

ImageResult.image = info[UIImagePickerController.InfoKey.editedImage] 为? UIImage

picker.dismiss(animated: true, succession: nil)

}

我遇到的问题是 imagePickerController 在照片后不显示相机图像被采取。 info.plist 已更新为具有所有正确的权限,我什至将源更改为 picker.sourceType = .photoLibrary ,它实际上显示了图像。

不确定其他人是否遇到过这个问题并知道答案,但我真的很感谢任何回应,甚至是建议,因为我觉得我已经用尽了所有途径。预先感谢您的任何帮助。

马蒂。

camera display problem

Hi all,

I am new to Swift so please bear with my as I try to explain my problem.

I am writing an App in XCode 13 that is supposed to take a photo and display it in a UIImageView simply named "ImageResult".

The following two functions perform the required tasks:

// Calls Camera (Works)

@objc private func TakePhoto(_ sender: Any) {

let picker = UIImagePickerController()

picker.sourceType = .camera

picker.allowsEditing = true

picker.delegate = self

present(picker, animated: true)
}

// Display Image From Camera (Doesn't work)

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

ImageResult.image = info[UIImagePickerController.InfoKey.editedImage] as? UIImage

picker.dismiss(animated: true, completion: nil)

}

The problem I am experiencing is that the imagePickerController does not display the camera image after the photo is taken. The info.plist has been updated with all the correct permissions and I have even gone to the extent of changing the source to picker.sourceType = .photoLibrary which does actually display the image.

Not sure if anyone else has experienced this problem and knows the answer but I really appreciate any response even suggestions as I feel as though I have exhausted all avenues. Thanks in advance for any help.

Matty.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舂唻埖巳落 2025-01-25 19:27:04

已经晚了但也许帮助了别人

DispatchQueue.main.async {
    ImageResult.image = info[UIImagePickerController.InfoKey.editedImage] as? UIImage
    
}

its late but maybe helped someone else

DispatchQueue.main.async {
    ImageResult.image = info[UIImagePickerController.InfoKey.editedImage] as? UIImage
    
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文