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

时间:2012-09-26 16:37:04

标签: ios ipad camera uiimagepickercontroller ios6

我有一个带有弹出窗口(UIPopoverController)的iPad应用程序,其中有多个视图被推送,其中一个有启动摄像头的按钮...见图像...

enter image description here

用这种方法煽动相机......

- (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的黑色条带...见图像......

enter image description here

虽然此应用程序现在针对iOS6,但我之前使用的是iOS5。任何人都可以想到解决方法或解决方法吗?

非常感谢迈克尔。

3 个答案:

答案 0 :(得分: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];
}

答案 1 :(得分: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的地方重新呈现popover - 在本例中是在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的人。

亲切的问候, 迈克尔。

答案 2 :(得分:0)

尝试

cameraImagePicker.modalPresentationStyle = UIModalPresentationFullScreen;

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