繁体   English   中英

当方向仅允许横向时,iOS 9 UIImagePickerControllerSourceTypePhotoLibrary崩溃

[英]iOS 9 UIImagePickerControllerSourceTypePhotoLibrary crash when orientation allow only Landscape

每当我调用UIImagePickerControllerSourceTypeCamera来使用相机拍照时,我就创建了仅支持横向方向的应用程序,但是当我调用UIImagePickerControllerSourceTypePhotoLibrary时,它崩溃了。

我曾尝试使用shouldAutoRotate()方法允许肖像,但仍然无法正常工作。 这个问题有什么解决办法吗?

当您在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。

我希望这有帮助。

modalPresentationStyleimagePickerController设置为UIModalPresentationCurrentContext ,然后将其呈现。 就像是,

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;

将Presentviewcontroller代码放入NSOperationQueue

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

我给你解决方案

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

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM