UIImagePickerControllerSourceType.SavedPhotosAlbum调用黑屏

时间:2014-11-17 21:27:01

标签: ios swift uiimagepickercontroller

我需要从用户图库中获取图片。这适用于UIImagePickerControllerSourceType.Camera,但当我用UIImagePickerControllerSourceType.SavedPhotosAlbum调用UIImagePickerController时,我得到一个黑色图像: The black screen got with UIImagePickerControllerSourceType.SavedPhotosAlbum

这是我的代码:

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        let picker : TGMImagePicker = segue.destinationViewController as TGMImagePicker
        if segue.identifier == "Camera" {
            picker.sourceType = UIImagePickerControllerSourceType.Camera
        } else if segue.identifier == "Library" {
            picker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
        }

        picker.setCaptureBlock { (image) -> Void in
            self.userImageView.image = image
        }
    }

1 个答案:

答案 0 :(得分:1)

哇,就在我发表评论时,我发现了一个解决方案。如果您还在寻找,我的关键是添加初始化pickercontroller的顶线:

if(segue.identifier == "presentCameraPicker"){
        var nextVC = cameraPickerController()
        nextVC = segue.destinationViewController as cameraPickerController
        nextVC.sourceType = UIImagePickerControllerSourceType.Camera
}else if(segue.identifier == "presentPhotoPicker"){
       var nextVC = cameraPickerController()
        nextVC = segue.destinationViewController as cameraPickerController
        nextVC.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
}

请注意,我在故事板中使用两个不同的segue到同一个视图控制器.. camerapicker的一个是模态演示,photopicker的一个是popover。