本文介绍了如何在swift中使用UIImagePickerController捕获相机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在swift中使用 UIImagePickerController
但是不能正常工作...
I'm trying use UIImagePickerController
in swift but isn't work...
我的ViewController:
my ViewController:
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)
}
}
}
我在以下代码行中有错误
I have errors in following line of code
imag.delegate = self
(Type'ViewControlles does confoorm to protocol 'UIImagePickerControllerDelegate')
imagePicker.mediaTypes = kUTTypeImage
(use of unresolved identifier kUTTypeImage)
我读过 kUTTypeImage
无法在swift中使用。但是不知道,我使用的是这个函数。有什么帮助?
I have read that kUTTypeImage
cant use in swift.but don't know, i am using bad this functions. Any help?
谢谢!!
推荐答案
你还应该导入控制器中的MobileCoreServices:
You should also import MobileCoreServices in the controller:
import MobileCoreServices
然后将类型放在方括号内,如下所示:
and then put the type inside square brackets like this:
image.mediaTypes = [kUTTypeImage]
Swift 2.0及更高
image.mediaTypes = [kUTTypeImage as String]
这篇关于如何在swift中使用UIImagePickerController捕获相机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!