if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)
    {

        var imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.Camera;
        //imagePicker.mediaTypes = kUTTypeImage
        imagePicker.allowsEditing = false

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

    }

我似乎无法迅速转换为kUTTypeImage,如果我注释掉了这行相机启动,但是屏幕是黑色的。有任何想法吗?这是 objective-c 语法:
imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];

最佳答案

显然就是这么简单:

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)
{
    var imagePicker = UIImagePickerController()
    imagePicker.delegate = self
    imagePicker.sourceType = UIImagePickerControllerSourceType.Camera;
    imagePicker.mediaTypes = [kUTTypeImage]
    imagePicker.allowsEditing = false

    self.presentViewController(imagePicker, animated: true, completion: nil)
}

10-06 02:54