Show UIImagePickerViewController for uiimagepickercontrollersourcetypephotolibrary from UIActionSheet in iPad

I have UIActionSheet

one that has options to select an image from a camera or photo library. For this I took the imagePickerViewController . For the camera, it works absolutely fine. But not for the photo library.

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 0) 
    {

        imgController = [[UIImagePickerController alloc] init];
        imgController.allowsEditing = YES;
        imgController.sourceType =  UIImagePickerControllerSourceTypeCamera;   
        imgController.delegate=self;
        [self presentModalViewController:imgController animated:YES];

    } 
    else if (buttonIndex == 1) 
    {

        if ([self.popoverController isPopoverVisible]) {
            [self.popoverController dismissPopoverAnimated:YES];
            [popoverController release];
        } else {
            if ([UIImagePickerController isSourceTypeAvailable:
                 UIImagePickerControllerSourceTypeSavedPhotosAlbum])
            {
                UIImagePickerController *imagePicker =
                [[UIImagePickerController alloc] init];
                imagePicker.delegate = self;
                imagePicker.sourceType =
                UIImagePickerControllerSourceTypePhotoLibrary;
                imagePicker.allowsEditing = NO;

                self.popoverController = [[UIPopoverController alloc]
                                          initWithContentViewController:imagePicker];

                self.popoverController.delegate = self;

                [self.popoverController setPopoverContentSize:CGSizeMake(500, 500)];

                [self.popoverController presentPopoverFromRect:self.view.frame 
                                                          inView:self.view
                                        permittedArrowDirections:UIPopoverArrowDirectionAny 
                                                        animated:YES];


                [imagePicker release];
            }
        }


    } 

}  

      

When the photo library option is touched, a small popupViewController view is created on top of the view, but it is very small. Why is popupViewController too small? Is there any other way to display UIImagePickerViewController

for uiimagepickercontrollersourcetypephotolibrary

?

+3


source to share


4 answers


Try this example



   CGRect popoverRect = [self.view convertRect:[self.view frame] 
                                       fromView:[self.view superview]];

    popoverRect.size.width = MIN(popoverRect.size.width, 80) ; 
    popoverRect.origin.x  = popoverRect.origin.x+150; 

    [self.popoverController 
     presentPopoverFromRect:popoverRect 
     inView:self.view 
     permittedArrowDirections:UIPopoverArrowDirectionLeft
     animated:YES];

      

+3


source


I think that the rectangle you are traversing should be smaller, not the size of the entire view:



CGRect popFrom = CGRectMake (CGPointMake(50,50),10,10);
[self.popoverController presentPopoverFromRect:popFrom 
                                                          inView:self.view
                                        permittedArrowDirections:UIPopoverArrowDirectionAny 
                                                        animated:YES];

      

+1


source


Try it without setting PopoverContentSize

for the UIImagePickerViewController

one presented in the popover - I think it took care of it automatically! It also appears CGRect

to presentPopoverFromRect:

be incorrect because you are passing in a frame view

that is converted to a popover pointing roughly to the center of the screen. You might want to set this in the border of the button that presented UIActionSheet

!

+1


source


Try the following:

 imagePickerController = [[UIImagePickerController alloc] init];
 imagePickerController.delegate = self;
 imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
 [self presentModalViewController:imagePickerController animated:YES];   

      

-1


source







All Articles