0

I had create app which only support Landscape orientation, whenever I called UIImagePickerControllerSourceTypeCamera to take picture using camera is worked, but when I called UIImagePickerControllerSourceTypePhotoLibrary it crashed.

I had tried using method shouldAutoRotate() to allow portrait but still not working. Any solution for this problem ?

victorz
  • 39
  • 1
  • 12

4 Answers4

2

As you are getting this error on iPad

Try the below code and use UIModalPresentationStyle for this purpose :-

                self.imagepicker.modalPresentationStyle = UIModalPresentationStyle.Popover
                let popover = self.imagepicker.popoverPresentationController
                self.imagepicker.preferredContentSize = CGSizeMake(400 ,400)
                popover!.sourceView = self.view
                popover!.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds),0,0)
                popover!.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
                self.presentViewController(self.imagepicker, animated: true, completion: nil)

This is in Swift, I hope you can covert to objective-c easily.

I hope this helps.

Deepak Sharma
  • 373
  • 3
  • 16
0

Set modalPresentationStyle of your imagePickerController to UIModalPresentationCurrentContext and then present it. Something like,

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
0

Put Presentviewcontroller code in NSOperationQueue

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
            self.presentViewController(self.imagepicker, animated: true, completion: nil)
    }];
Pinank Lakhani
  • 1,109
  • 2
  • 11
  • 31
0

I give you the solution

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.wantsFullScreenLayout = YES;

    UIPopoverController *imagePopover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
    [imagePopover setDelegate:self];
    [imagePopover setPopoverContentSize:CGSizeMake(320, 500) animated:NO];  //set your content size
    [imagePopover presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];   //I give presentPopoverFromRect as button frame.Change here what you want

}
user3182143
  • 9,459
  • 3
  • 32
  • 39