gpt4 book ai didi

ios - UIImagePicker 源类型不想改变

转载 作者:行者123 更新时间:2023-11-28 16:04:14 25 4
gpt4 key购买 nike

为了开发应用,我设置了一个带有 .savedPhotosAlbum 的 UIImagePicker 作为源类型。

import UIKit

class PictureViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

/////////////////// OUTLETS ////////////////////
///////////////// PROPERTIES ///////////////////
var imagePicker = UIImagePickerController()

override func viewDidLoad() {
super.viewDidLoad()

imagePicker.delegate = self

}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// Where do we want our photos from and we don't want edited photos
imagePicker.allowsEditing = false
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.cameraCaptureMode = .photo
imagePicker.modalPresentationStyle = .fullScreen

// Let's take the image from the picker
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
snapImage.image = image

// When the user picks a picture, disabling the background color of the UIImageView
snapImage.backgroundColor = UIColor.clear

// Closing the image picker
imagePicker.dismiss(animated: true, completion: nil)
}

@IBAction func cameraTapped(_ sender: Any) {
present(imagePicker, animated: true, completion: nil)
}

现在我的应用已经完成,我想在我的 Iphone 上试用我的应用,所以我改变了这个:

imagePicker.sourceType = .savedPhotosAlbum

imagePicker.sourceType = UIImagePickerControllerSourceType.camera

我已经在我的 info.plist 中添加了

<key>NSCameraUsageDescription</key>
<string>We want to access your camera to ...</string>

但是当我尝试拍照时,它一直显示我的相册,这就是问题所在。我希望能够从手机的相机中拍照。

最佳答案

你需要输入这段代码

imagePicker.allowsEditing = false
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.cameraCaptureMode = .photo
imagePicker.modalPresentationStyle = .fullScreen

viewDidLoadcameraTapped

问题 - 现在您将此代码放在 UIImagePicker 的委托(delegate)方法中,该方法在选择图像或拍摄图像后被调用。

关于ios - UIImagePicker 源类型不想改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40533536/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com