我有一个视图控制器,需要能够从相册和相机中选择一张图片。我只能为didFinishPickingMediaWithInfo提供一个委托方法,虽然我可以判断它是否是一个图像,我似乎无法判断它是来自相册还是来自相机(我需要先将它保存在相册中)。信息中有什么可以帮我区分这两个吗?
...谢谢
答案 0 :(得分:51)
因为UIImagePickerController
已传递给方法,所以您只需要:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
// Do something with an image from the camera
} else {
// Do something with an image from another source
}
}
答案 1 :(得分:9)
在Swift3中:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
if picker.sourceType == .camera {
// Do something with an image from the camera
}
else {
// Do something with an image from another source
}
}