繁体   English   中英

如何快速打开电影画廊

[英]How to open movie gallery in swift

我正在尝试在ipad上打开电影的画廊,但出现此错误,我不知道为什么。

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type must be UIImagePickerControllerSourceTypeCamera'

这是我的代码:

func GaleriaVideo() {
   if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum) {
        println("Galeria Video")

        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
        imagePicker.mediaTypes = [kUTTypeMovie]
        imagePicker.allowsEditing = false

        imagePicker.showsCameraControls = false

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

类似的代码对我来说适用于照相馆,但我不知道为什么这不起作用。

您能告诉我我的代码有什么问题吗,或者我必须搜索才能做到这一点? 我几天前正在尝试这个,我感到迷茫。

谢谢,

编辑:

这是我的照相馆,它的工作原理是:

    func GaleriaImagen() {

    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum){
        println("Galeria Imagen")

        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
        imagePicker.allowsEditing = false

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

    }
}
func imagePickerControllerDidCancel(picker: UIImagePickerController!) {

    self.dismissViewControllerAnimated(false, completion: nil)
}

func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!) {
    self.dismissViewControllerAnimated(true, completion: nil)
}

尝试这个

func GaleriaVideo() {
   if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum) {
        println("Galeria Video")

        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
        imagePicker.mediaTypes = [kUTTypeMovie]
        imagePicker.allowsEditing = false

        imagePicker.showsCameraControls = false

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

添加: UINavigationControllerDelegate, UIImagePickerControllerDelegate

func gallery() {
  if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary) {
    var img = UIImagePickerController()
    img.delegate = self
    img.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
    //img.mediaTypes = [kUTTypeImage]; //whatever u want type
    img.allowsEditing = false
    self.presentViewController(img, animated: true, completion: nil)
  }
}

func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!) {
  self.dismissViewControllerAnimated(true, completion: nil)    
}

扩大对Aju的回答,这将迅速2

func GaleriaVideo() {
  if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum){
    print("Galeria Video")
    imagePicker.delegate = self
    imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
    imagePicker.mediaTypes = [kUTTypeMovie as String]
    imagePicker.allowsEditing = false
    self.presentViewController(imagePicker, animated: true, completion: nil)
  }
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
  self.dismissViewControllerAnimated(true, completion: nil)
  //Here you can manipulate the adquired video
}

斯威夫特3/4:

func GaleriaImagen() {        
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.savedPhotosAlbum){
            print("Galeria Imagen")
            imagePicker.delegate = self
            imagePicker.sourceType = UIImagePickerControllerSourceType.savedPhotosAlbum
            imagePicker.allowsEditing = false
            imagePicker.modalPresentationStyle = .custom
            self.present(self.imagePicker, animated: true, completion: nil)
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM