我想通过if语句检查是从相机胶卷中拾取图像还是由内置相机拍摄的。我怎么能通过if语句来做到这一点? 谢谢你的帮助!
代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
toolbar.hidden = NO;
}
if (picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
toolbar.hidden = NO;
}
if (picker.sourceType == UIImagePickerControllerSourceTypeSavedPhotosAlbum) {
toolbar.hidden = NO;
}
else{
toolbar.hidden = YES;
}
imgView.image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
[self dismissViewControllerAnimated:YES completion:nil];
}
答案 0 :(得分:4)
只需查看sourceType
:
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
//image taken with camera
}
else{
//image taken from camera roll
}
在imagePickerController:didFinishPickingMediaWithInfo:
方法中执行此操作。