UIImagePickerController与UIImagePickerControllerSourceTypeCamera显示黑屏

时间:2014-05-27 13:02:56

标签: ios iphone uiimagepickercontroller

当我提出UIImagePickerController来拍摄照片时,我遇到了一个随机问题。有时预览屏幕只是黑色。 (这可能是第一次,可能是第二次,或者可以永远,甚至永远不会)。然而,我可以看到相机控制,黄色方块可以进行人脸检测。 如果我等待一段时间(约20秒),黑色预览消​​失,预览出现......

以下是我有时会在日志中看到的内容:

  

快照未呈现的视图会导致空快照。确保在屏幕更新后快照或快照之前,您的视图至少呈现过一次。

config:xcode 5.1.1,iPhone 5 / 5S,ios 7.0 / 7.1

这是一个为我重现问题的代码:

-(void) showCamera
{ 
    UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
    pickerController.allowsEditing = NO;
    pickerController.sourceType     = UIImagePickerControllerSourceTypeCamera;
    pickerController.cameraDevice   = UIImagePickerControllerCameraDeviceFront;
    pickerController.cameraOverlayView = nil;

    UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
    while (topController.presentedViewController) {
        topController = topController.presentedViewController;
    }

    [topController presentViewController:pickerController animated:YES completion:nil];
}

当然,对于我的真实应用,我测试是否有相机:

[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]);

我发现了几个类似的问题,但没有任何真正的答案:

我已经尝试了他们的建议,但没有成功。

编辑:这里有更多代码: 如上所述,我创建了一个单例类,子类化UIImagePickerController:

@implementation BBImagePickerController

static BBImagePickerController *sharedInstance = nil;

+ (BBImagePickerController *) sharedInstance
{
    if (!sharedInstance)
        sharedInstance = [[BBImagePickerController alloc] init];

    return sharedInstance;
}

@end

然后,我使用UIActionSheet + BlocksKit从操作表的完成块中调用它:

UIActionSheet *actionSheetExt = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:cancel destructiveButtonTitle:nil otherButtonTitles:pickPic, takePic, nil];    
[actionSheetExt showInView:presentingViewController.view];

[actionSheetExt bk_setDidDismissBlock:^(UIActionSheet *actionSheet, NSInteger click) {        
    if (click == actionSheet.cancelButtonIndex)
    {
        NSLog(@"the user cancelled the action");
        return ;
    }   
    BBImagePickerController *pickerController = [BBImagePickerController sharedInstance];
    pickerController.allowsEditing = YES;
    pickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    pickerController.delegate = self;

    if (click == 1)
    {   // get from library
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
            pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    else if (click == 2)
    {
        // take a picture
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            pickerController.sourceType     = UIImagePickerControllerSourceTypeCamera;
            pickerController.cameraDevice   = UIImagePickerControllerCameraDeviceFront;
            //[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
        }
    }
    [presentingViewController presentViewController:pickerController animated:YES completion:^{
        NSLog(@"BBImagePickerController presented");
        // Black preview screen 
    }];
}];

0 个答案:

没有答案