gpt4 book ai didi

ios - swift ios 什么时候需要使用 mediaTypes kUTTypeImage

转载 作者:行者123 更新时间:2023-11-28 11:03:41 24 4
gpt4 key购买 nike

我的应用程序中有一个图像选择器,您可以在其中从相机胶卷中选择图像或拍摄新照片,然后将图像上传到我的后端服务器。

但是环顾其他人的代码,我发现有些人使用这个: imagePickerController.mediaTypes = [kUTTypeImage as String]

为什么要设置mediaTypes为kUTTypeImage?

我没有在下面的代码中使用它,但一切仍然正常

我通过 UIAlertController 选择像这样的图像:

//Check if camera exist
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
let cameraAction = UIAlertAction(title: "Take a photo", style: .Default) { (action) in
self.imagePicker.sourceType = .Camera
self.imagePicked = 1
self.presentViewController(self.imagePicker, animated: true, completion: nil)

}

alertController.addAction(cameraAction)
}

//Check if photo lib exist
if UIImagePickerController.isSourceTypeAvailable(.PhotoLibrary) {
let photosLibraryAction = UIAlertAction(title: "Pick image", style: .Default) { (action) in
self.imagePicker.sourceType = .PhotoLibrary
self.imagePicked = 1
self.presentViewController(self.imagePicker, animated: true, completion: nil)

}
alertController.addAction(photosLibraryAction)
}

然后我得到图像:

 func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {


if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
//Change aspect when not dummy image
self.bigImage.contentMode = .ScaleAspectFill
self.bigImage.clipsToBounds = true
self.bigImage.image = pickedImage

最佳答案

kUTTypeImage 实际上是 mediaTypes 属性的默认值。它指出,只能选择静止图像。如果您接受此默认值,则无需在代码中显式设置它。

这是文档:https://developer.apple.com/reference/uikit/uiimagepickercontroller/1619173-mediatypes

关于ios - swift ios 什么时候需要使用 mediaTypes kUTTypeImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39598000/

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