我需要从用户图库中获取图片。这适用于UIImagePickerControllerSourceType.Camera,但当我用UIImagePickerControllerSourceType.SavedPhotosAlbum调用UIImagePickerController时,我得到一个黑色图像:
这是我的代码:
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
}
}
答案 0 :(得分:1)
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。