0

我有一个 iPad 应用程序,它有一个弹出窗口(UIPopoverController),其中有多个视图被推送,其中一个有一个启动相机的按钮......看图片......

在此处输入图像描述

相机是用这种方法煽动的……

- (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 上也得到了同样的效果。任何人都可以想到解决方法或修复方法吗?

非常感谢,迈克尔。

4

3 回答 3

1

我们怀疑这与状态栏高度有关,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];
 }

可能必须向以下每个委托添加以下代码:-imagePickerControllerDidCancel和.didFinishPickingMediaWithInfofinishedSavingWithError

if (IS_IPAD)
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}
于 2013-08-02T21:56:31.730 回答
0

尝试

cameraImagePicker.modalPresentationStyle = UIModalPresentationFullScreen;

这将告诉 UIImagePickerController 实例呈现样式并修复此错误。

于 2013-09-13T17:51:49.283 回答
0

按照从 shawnwall 的评论到原始问题的指针,我设法通过在根 UIViewController 上执行 presentViewController 方法调用来解决此问题,然后在拍照的任一侧解除并重新建立 UIPopoverController。

所以,我有我的方法来激发相机视图......(注意最后的两行是新的 - 第一行关闭弹出框,第二行在主根 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:^{}];
}

然后,我在我解除 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];
}

这工作正常 - 相机视图的关闭和弹出框的重新呈现可能会更整洁一些,因为弹出框重新出现,而相机从屏幕底部动画出来,如果弹出框出现在相机之后看起来会更好过渡了,但对我来说,目前这不是一个大问题。

希望这对想要从 UIPopoverController 打开全屏相机 UIImagePickerController 的人有所帮助。

亲切的问候,迈克尔。

于 2012-09-27T12:40:22.743 回答