如何通过popoverview控制器显示imagepickercontroller?

时间:2012-10-04 11:16:43

标签: objective-c ios ipad uiimagepickercontroller

我使用以下代码从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上工作。 提前谢谢。

1 个答案:

答案 0 :(得分:1)

- (IBAction为)Click_event   {

UIImagePickerController *imagePickerController_=[[UIImagePickerController alloc] init];
    UIPopoverController *popover_=[[UIPopoverController alloc] initWithContentViewController:imagePickerController_];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        imagePickerController_.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[popover_ presentPopoverFromRect:CGRectMake(400, 400, 0, 0) inView:self.Mybutton
                permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];


   }

 }