从popup窗口打开全屏模式时,相机的屏幕位置不正确

我有一个iPad应用程序有一个popup式窗口(UIPopoverController)与一些视图推,其中之一有一个button,启动相机…见图像…

在这里输入图像说明

相机是用这种方法煽动…

- (IBAction)selectPlanImageFromCamera:(id)sender { [self.blockTextField resignFirstResponder]; [self.levelTextField resignFirstResponder]; [self.zoneNamePrefixTextField resignFirstResponder]; [self.nameTextField resignFirstResponder]; [self.notesTextView resignFirstResponder]; imagePicker = [[UIImagePickerController alloc] init]; imagePicker.allowsEditing = NO; imagePicker.delegate = self; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.modalPresentationStyle = UIModalPresentationFullScreen; imagePicker.showsCameraControls = YES; [self presentViewController:imagePicker animated:YES completion:^{}]; } 

然后我得到全屏模式摄像头视图显示,这是所有预期的一部分,因为它的位置略低于屏幕边界的事实。 这意味着底部的控件在屏幕的南边20px处,屏幕的顶部有一个20px的黑色边框…查看图片…

在这里输入图像说明

虽然这个应用程序现在是iOS6的目标,我以前用iOS5获得相同的效果。 任何人都可以想到一个解决方法或修复?

非常感谢,迈克尔。

我们怀疑这和状态栏高度20px 。 我们的猜测是正确的,下面的代码为我们隐藏状态栏,而UIIMagePickerController显示。

  UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil]; imagePicker.allowsEditing = NO; if (IS_IPAD) { imagePicker.modalPresentationStyle = UIModalPresentationFullScreen; [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; [self presentViewController:imagePicker animated:YES completion:nil]; } 

可能需要在下面的代码中添加代码: imagePickerControllerDidCanceldidFinishPickingMediaWithInfofinishedSavingWithError

 if (IS_IPAD) { [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]; } 

在shawnwall的注释指向原始问题之后,我设法通过在根UIViewController上执行presentViewController方法调用来解决此问题,然后closures并重新build立UIPopoverController拍摄照片。

所以,我有我的方法煽动照相机视图…(注意最后两行是新的 – 第一行closurespopup窗口,第二行显示主UIViewController上的UIImagePickerController)

 - (IBAction)selectPlanImageFromCamera:(id)sender { [self.blockTextField resignFirstResponder]; [self.levelTextField resignFirstResponder]; [self.zoneNamePrefixTextField resignFirstResponder]; [self.nameTextField resignFirstResponder]; [self.notesTextView resignFirstResponder]; cameraImagePicker = [[NonRotatingUIImagePickerController alloc] init]; cameraImagePicker.allowsEditing = NO; cameraImagePicker.delegate = self; cameraImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; cameraImagePicker.modalPresentationStyle = UIModalPresentationFullScreen; cameraImagePicker.showsCameraControls = YES; [mainCanvasViewController.sitePopoverController dismissPopoverAnimated:YES]; [mainCanvasViewController presentViewController:cameraImagePicker animated:YES completion:^{}]; } 

然后,我重新呈现popup式窗口,我解雇了UIImagePickerController – 在这种情况下didFinishPickingMediaWithInfo委托方法(在上述相同的UIViewController)…

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { if ([info objectForKey:UIImagePickerControllerMediaType] == (NSString *)kUTTypeImage) { ... // image handling } [picker dismissViewControllerAnimated:YES completion:^{}]; UIBarButtonItem *tappedButton = mainCanvasViewController.navigationItem.leftBarButtonItem; [mainCanvasViewController.sitePopoverController presentPopoverFromBarButtonItem:tappedButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } 

这工作正常 – closures相机视图和重新展示的popover可能会有点整洁,因为popup窗口重新出现,而相机是在屏幕底部animation,如果popover出现在相机后,它会更好看过渡了,但对我而言,目前这不是一个大问题。

希望这可以帮助那些想从UIPopoverController打开全屏摄像头UIImagePickerController的人。

亲切的问候,迈克尔。

尝试

cameraImagePicker.modalPresentationStyle = UIModalPresentationFullScreen;

这将告诉UIImagePickerController实例的演示风格,并修复这个错误。