1

カメラやフォトライブラリを使って写真を撮る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のポップオーバー内にカメラを表示することは可能ですか?ありがとう。

4

2 に答える 2

4

以下は、iPadでカメラを全画面表示する方法に関するOPのコメントに回答しています。

コードを次のように変更します。

- (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;
        imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;

        [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];
    }
}
于 2013-03-04T18:09:19.823 に答える