Сбой UIImagePickerControllerSourceTypePhotoLibrary iOS 9, когда ориентация разрешает только альбомную ориентацию

У меня было приложение, которое поддерживает только альбомную ориентацию, всякий раз, когда я вызывал UIImagePickerControllerSourceTypeCamera, чтобы сделать снимок с помощью камеры, он работал, но когда я вызывал UIImagePickerControllerSourceTypePhotoLibrary, он зависал.

Я пытался использовать метод shouldAutoRotate(), чтобы разрешить портрет, но все еще не работал. Любое решение этой проблемы?


person victorz    schedule 13.10.2016    source источник
comment
Не могли бы вы поделиться фрагментом кода?   -  person Jitendra Modi    schedule 13.10.2016
comment
Попробуйте следующее: - (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskLandscape; } Вместо shouldAutoRotate()   -  person Yogesh Mv    schedule 13.10.2016


Ответы (4)


Как вы получаете эту ошибку на iPad

Попробуйте приведенный ниже код и используйте для этой цели UIModalPresentationStyle:

                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)

Это в Swift, я надеюсь, вы легко сможете перейти к Objective-C.

Надеюсь, это поможет.

person Deepak Sharma    schedule 13.10.2016

Установите modalPresentationStyle вашего imagePickerController на UIModalPresentationCurrentContext, а затем предъявите его. Что-то типа,

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
person Ketan Parmar    schedule 13.10.2016

Поместите код Presentviewcontroller в NSOperationQueue

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
            self.presentViewController(self.imagepicker, animated: true, completion: nil)
    }];
person Pinank Lakhani    schedule 13.10.2016

Я даю вам решение

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

}
person user3182143    schedule 13.10.2016