我创建的应用程序只支持横向方向,每当我调用UIImagePickerControllerSourceTypeCamera使用相机拍照时,都会工作,但是当我调用UIImagePickerControllerSourceTypePhotoLibrary时它会崩溃。
我曾尝试使用方法shouldAutoRotate()来允许纵向但仍无效。解决这个问题的任何方法?
答案 0 :(得分:2)
当您在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)
这是在斯威夫特,我希望你能轻易地转向目标-c。
我希望这会有所帮助。
答案 1 :(得分:0)
将modalPresentationStyle
的{{1}}设置为imagePickerController
然后展示。像,
UIModalPresentationCurrentContext
答案 2 :(得分:0)
将Presentviewcontroller代码放在NSOperationQueue
中[[NSOperationQueue mainQueue] addOperationWithBlock:^{
self.presentViewController(self.imagepicker, animated: true, completion: nil)
}];
答案 3 :(得分:0)
我给你解决方案
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
}