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

前端之家收集整理的这篇文章主要介绍了如何使用UIImagePickerController在swift中捕获相机?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在swift中使用UIImagePickerController,但不工作…

我的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)

    }
   }   
}

我在以下代码行中有错误

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

我已经阅读kUTTypeImage不能使用在swift.but不知道,我使用坏的这个功能。任何帮助?

谢谢!!

您还应该在控制器中导入MobileCoreServices:
import MobileCoreServices

然后将类型放在方括号中,如下所示:

imag.mediaTypes = [kUTTypeImage]
原文链接:https://www.f2er.com/swift/320833.html

猜你在找的Swift相关文章