加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 06:00:20 所属栏目:百科 来源:网络整理
导读:我试图在swift中使用UIImagePickerController,但不工作… 我的ViewController: class ViewController: UIViewController {@IBOutlet var imag : UIView = nil@IBAction func capture(sender : UIButton) { println("Button capture") if UIImagePickerCont
我试图在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]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读