【问题标题】:Camera has incorrect screen placement when open fullscreen modal from popover从弹出窗口打开全屏模式时,相机的屏幕位置不正确
【发布时间】:2012-09-26 16:37:04
【问题描述】:

我有一个 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 中获得了相同的效果。谁能想到解决方法或修复方法?

非常感谢,迈克尔。

【问题讨论】:

  • 您可能需要从视图层次结构中更高的 vc 呈现。您可以使用委托呼叫或通知中心,并尝试从更高的 vc 显示。
  • 感谢指针'shawnwall' - 这引导我走向正确的方向。我将发布我的最终解决方案作为答案。
  • 我遇到了类似的问题...通过使用 [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; 解决了它

标签: ios ipad camera uiimagepickercontroller ios6


【解决方案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];
 }

可能需要为以下每个代表添加以下代码:- imagePickerControllerDidCanceldidFinishPickingMediaWithInfofinishedSavingWithError

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

【讨论】:

    【解决方案2】:

    按照从 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 的人有所帮助。

    亲切的问候, 迈克尔。

    【讨论】:

      【解决方案3】:

      试试

      cameraImagePicker.modalPresentationStyle = UIModalPresentationFullScreen;

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

      【讨论】:

        猜你喜欢
        • 2013-06-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-04
        相关资源
        最近更新 更多