【发布时间】: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