次のコードを使用して iPhone のアルバムから写真を取得しましたが、「UIImagePickerController は UIPopoverController 経由で提示する必要があります」というエラーが表示されます。
- (void)showImagePicker:(UIImagePickerControllerSourceType)sourceType
{
if ([UIImagePickerController isSourceTypeAvailable:sourceType])
{
[self setupImagePicker:sourceType];
[self presentModalViewController:imagePickerController animated:YES];
}
}
- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType
{
imagePickerController.sourceType = sourceType;
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
// user wants to use the camera interface
//
imagePickerController.showsCameraControls = NO;
if (imagePickerController.cameraOverlayView != self.view)
{
// setup our custom overlay view for the camera
//
// ensure that our custom view's frame fits within the parent frame
CGRect overlayViewFrame = imagePickerController.cameraOverlayView.frame;
CGRect newFrame = CGRectMake(0.0,
CGRectGetHeight(overlayViewFrame) -
self.view.frame.size.height - 9.0,
CGRectGetWidth(overlayViewFrame),
self.view.frame.size.height + 9.0);
self.view.frame = newFrame;
imagePickerController.cameraOverlayView = self.view;
}
}
}
-(IBAction)getPhoto:(id)sender {
imagePickerController = [[UIImagePickerController alloc] init];
[self showImagePicker:UIImagePickerControllerSourceTypePhotoLibrary];
}
iPadで動作するように私のコードを変更してください。前もって感謝します。