【问题标题】:UIImagePicker source type doesn't want to changeUIImagePicker 源类型不想改变
【发布时间】:2016-11-10 17:21:15
【问题描述】:

为了开发应用,我设置了一个带有.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>

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

【问题讨论】:

  • 您需要添加更多上下文,因此将代码放在您正在检查设备并显示picker的位置
  • @Santosh 第一次发布有关 IOS 的帖子抱歉,我已经添加了所有我所拥有的

标签: ios swift camera uiimagepickercontroller


【解决方案1】:

你需要输入这段代码

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

viewDidLoadcameraTapped

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

【讨论】:

  • 非常感谢您的解决方案和解释!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 2011-07-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多