gpt4 book ai didi

uiimagepickercontroller - 如何在 swift 中使用 UIImagePickerController 捕获相机?

转载 作者:IT王子 更新时间:2023-10-29 05:02:47 27 4
gpt4 key购买 nike

我正在尝试快速使用 UIImagePickerController 但不起作用...

我的 View Controller :

class ViewController: UIViewController {

@IBOutlet var imag : UIView = nil
@IBAction func capture(sender : UIButton) {
println("Button capture")
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)
{
var imag = UIImagePickerController()
imag.delegate = self
imag.sourceType = UIImagePickerControllerSourceType.Camera;
imag.mediaTypes = kUTTypeImage
imag.allowsEditing = false

self.presentViewController(imag, animated: true, completion: nil)

}
}
}

我在下面的代码行中有错误

imag.delegate = self 
(Type'ViewControlles does confoorm to protocol 'UIImagePickerControllerDelegate')
imagePicker.mediaTypes = kUTTypeImage
(use of unresolved identifier kUTTypeImage)

我读过 kUTTypeImage 无法在 swift 中使用。但我不知道,我使用的这个函数很糟糕。有帮助吗?

谢谢!!

最佳答案

您还应该在 Controller 中导入 MobileCoreServices:

import MobileCoreServices 

然后像这样将类型放在方括号内:

image.mediaTypes = [kUTTypeImage]

Swift 2.0 及更高版本

image.mediaTypes = [kUTTypeImage as String]

关于uiimagepickercontroller - 如何在 swift 中使用 UIImagePickerController 捕获相机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24262990/

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