私は同じ問題を抱えていましたが、この方法で解決しました。
写真を撮る場合
1)カメラから(両方ともUINavigationcontrollerとして開く)2)ギャラリーから(ipadの場合はUIpopovercontrollerとして開き、iphoneの場合はnvigationcontrollerとして開く)
最初のセットデリゲート
@interface camera : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate,UIPopoverControllerDelegate>
カメラから画像を取得した後
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = YES;
imagePicker.wantsFullScreenLayout = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
newMedia = YES;
iscamera = 0;
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error to access Camera"
message:@""
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
&ギャラリーから画像を取得
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *_picker=nil;
if (popoverController) {
[popoverController dismissPopoverAnimated:NO];
}
_picker = [[UIImagePickerController alloc] init];
_picker.delegate = self;
_picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
_picker.wantsFullScreenLayout = YES;
//[popoverController presentPopoverFromBarButtonItem:sender
// permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[self presentViewController:_picker animated:YES completion:nil];
} else
{
popoverController = [[UIPopoverController alloc] initWithContentViewController:_picker];
[popoverController setDelegate:self];
[popoverController presentPopoverFromRect:btn.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionLeft
animated:YES];
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error access photo library"
message:@"your device non support photo library"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
デリゲートメソッドで得られる両方の結果
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
}