カメラやフォトライブラリを使って写真を撮るiOSアプリを書こうとしています。これは私の最初のiOSアプリなので、経験がありません。iPhoneでそれを行う方法の例をいくつか見つけ、モーダルウィンドウ呼び出しpresentViewController
をに置き換えましたIUPopoverController
。これはフォトライブラリ(imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary
)では正常に機能しますが、カメラ(imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera
)では次のエラーが発生します。
Terminating app due to uncaught exception 'NSGenericException', reason: 'The content view controller argument must be the root of its associated view controller hierarchy.'
iOS6.1用のXcode4.6テストを使用
私のコード:
- (void) useCamera:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
_popover = [[UIPopoverController alloc] initWithContentViewController: imagePicker];
[_popover presentPopoverFromRect: _popoverCenter inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
else
{
[self presentViewController:imagePicker
animated:YES completion:nil];
}
_newMedia = YES;
}
else
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Camera failed to open"
message: @"Camera is not available"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
iPadのポップオーバー内にカメラを表示することは可能ですか?ありがとう。