Objective c iOS 8快照尚未渲染的视图将导致空快照

Objective c iOS 8快照尚未渲染的视图将导致空快照,objective-c,ios8,uiimagepickercontroller,xcode,Objective C,Ios8,Uiimagepickercontroller,Xcode,在iOS 8中,我在从相机捕获图像时遇到问题,直到现在我使用此代码 UIImagePickerController *controller=[[UIImagePickerController alloc] init]; controller.videoQuality=UIImagePickerControllerQualityTypeMedium; controller.delegate=(id)self; controller.sourceType=UIImagePickerControlle

在iOS 8中,我在从相机捕获图像时遇到问题,直到现在我使用此代码

UIImagePickerController *controller=[[UIImagePickerController alloc] init];
controller.videoQuality=UIImagePickerControllerQualityTypeMedium;
controller.delegate=(id)self;
controller.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:controller animated:YES completion:nil];
但在iOS 8中,我得到了以下信息:

Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
我已尝试使用with提供的解决方案

还有这个

...
controller.modalPresentationStyle=UIModalPresentationFullScreen;
or
controller.modalPresentationStyle=UIModalPresentationCurrentContext;
...
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [self presentViewController:controller animated:YES completion:nil];
});
[self presentViewController:controller animated:YES completion:NULL];
[self presentViewController:controller animated:YES completion:^{

}];
还有这个

...
controller.modalPresentationStyle=UIModalPresentationFullScreen;
or
controller.modalPresentationStyle=UIModalPresentationCurrentContext;
...
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [self presentViewController:controller animated:YES completion:nil];
});
[self presentViewController:controller animated:YES completion:NULL];
[self presentViewController:controller animated:YES completion:^{

}];
还有这个

...
controller.modalPresentationStyle=UIModalPresentationFullScreen;
or
controller.modalPresentationStyle=UIModalPresentationCurrentContext;
...
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [self presentViewController:controller animated:YES completion:nil];
});
[self presentViewController:controller animated:YES completion:NULL];
[self presentViewController:controller animated:YES completion:^{

}];
还有这个

...
controller.modalPresentationStyle=UIModalPresentationFullScreen;
or
controller.modalPresentationStyle=UIModalPresentationCurrentContext;
...
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [self presentViewController:controller animated:YES completion:nil];
});
[self presentViewController:controller animated:YES completion:NULL];
[self presentViewController:controller animated:YES completion:^{

}];

有什么想法吗?

我很确定这只是iOS 8.0中的一个bug。它可以通过最简单的POC应用程序复制,这些应用程序只不过是像上面那样尝试呈现一个
UIImagePickerController
。此外,据我所知,除了显示图像选择器/摄像机外,没有其他模式可供选择。你甚至可以下载苹果的,运行它,它会立即产生同样的错误


也就是说,这个功能对我来说仍然有效。除了警告/错误之外,您的应用程序的功能是否存在问题?

我一直在努力解决这个问题,几个小时以来,我阅读了所有相关主题,发现错误是因为在我设备的隐私设置下,摄像头对我的应用程序的访问被阻止!!!我从来没有拒绝过使用摄像头,我不知道它是如何被阻止的,但这就是问题所在

我也遇到了同样的问题,我通过检查摄像头是否可用来解决它:

BOOL cameraAvailableFlag = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
    if (cameraAvailableFlag)
        [self performSelector:@selector(showcamera) withObject:nil afterDelay:0.3];

我发现了同样的问题并尝试了一切。我有两个不同的应用程序,一个在objective-C中,一个在swift中,它们都有相同的问题。错误消息出现在调试器中,第一张照片后屏幕变黑。这只发生在iOS>=8.0中,显然这是一个bug

我找到了一个困难的解决办法。使用imagePicker.showsCameraControls=false关闭相机控件,并创建自己的覆盖视图,其中包含缺少的按钮。关于如何做到这一点,有各种各样的教程。
奇怪的错误消息仍然存在,但至少屏幕没有变黑,并且您有一个正常工作的应用程序。

我在调用UIImagePickerController presentViewController:从回调到UIAlertView委托后遇到了这个问题。我通过推动presentViewController解决了这个问题:使用dispatch\u async取消当前执行跟踪

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    dispatch_async(dispatch_get_main_queue(), ^{
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.delegate = self;

        if (buttonIndex == 1)
            imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        else
            imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

        [self presentViewController: imagePickerController
                           animated: YES
                         completion: nil];
    });
}

我在设置一些视图的动画时遇到了这个问题,应用程序将进入背景模式并返回。我通过设置一个标志isActive来处理它。我把它设为“否”

- (void)applicationWillResignActive:(UIApplication *)application
是的

- (void)applicationDidBecomeActive:(UIApplication *)application

并相应地设置或不设置视图的动画。已解决此问题。

这可能是内置ImagePickerController的一个错误。我的代码正常工作,但在iPhone6Plus上偶尔会崩溃

UIImagePickerControllerSourceType source = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
UIImagePickerController *cameraController = [[UIImagePickerController alloc] init];
        cameraController.delegate = self;
        cameraController.sourceType = source;
        cameraController.allowsEditing = YES;
        [self presentViewController:cameraController animated:YES completion:^{
            //iOS 8 bug.  the status bar will sometimes not be hidden after the camera is displayed, which causes the preview after an image is captured to be black
            if (source == UIImagePickerControllerSourceTypeCamera) {
                [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
            }
        }];

我尝试过其他答案所建议的所有解决方案,但都没有成功。切换到后问题终于解决。

我遇到了这个问题。当我们调用相机并释放此问题产生的视图时。例如,在ViewDidDemouse方法中调用camera并设置view nil,由于camera事件没有回调,因此会出现此错误。对于此错误,也请确保此情况。

对于在图像捕获后看到黑色预览问题的任何人,在显示UIPickerController后隐藏状态栏似乎可以解决此问题

UIImagePickerControllerSourceType source = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
UIImagePickerController *cameraController = [[UIImagePickerController alloc] init];
        cameraController.delegate = self;
        cameraController.sourceType = source;
        cameraController.allowsEditing = YES;
        [self presentViewController:cameraController animated:YES completion:^{
            //iOS 8 bug.  the status bar will sometimes not be hidden after the camera is displayed, which causes the preview after an image is captured to be black
            if (source == UIImagePickerControllerSourceTypeCamera) {
                [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
            }
        }];

我没有足够的声誉点数来评论@greg的上述回答,因此我将在这里添加我的观察结果。我有一个针对iPad和iPhone的Swift项目。我的主视图控制器中有一个方法(下面的相关部分)。当我在手机上测试时,一切正常,不会产生任何警告。当我在iPad上运行它时,一切正常,但我看到了关于快照视图的警告。然而,有趣的是,当我在没有使用popover控制器的情况下在iPad上运行时,一切正常,没有任何警告。不幸的是,苹果公司规定,如果不使用相机,图像采集器必须在iPad上的popover中使用

    dispatch_async(dispatch_get_main_queue(), {
        let imagePicker: UIImagePickerController = UIImagePickerController();
        imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum;
        imagePicker.mediaTypes = [kUTTypeImage];
        imagePicker.allowsEditing = false;
        imagePicker.delegate = self;

        if(UIDevice.currentDevice().userInterfaceIdiom == .Pad){ // on a tablet, the image picker is supposed to be in a popover
            let popRect: CGRect = buttonRect;
            let popover: UIPopoverController = UIPopoverController(contentViewController: imagePicker);
            popover.presentPopoverFromRect(popRect, inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Up, animated: true);
        }else{
            self.presentViewController(imagePicker, animated: true, completion: nil);
        }
    });

我什么都试过了,我的问题是相机和照片库的图像采集器在它们出现后立即消失了。我用下面这句话解决了它(swift)


我也有同样的错误,在打开相机的时候在控制台里收到了下面的信息

'对尚未渲染的视图进行快照将导致空快照。确保您的视图在快照之前或屏幕更新之后至少呈现一次。”

对我来说,问题在于Info.plist文件中的捆绑显示名称。它是空的。我如何将我的应用程序名称放在那里,现在它工作正常。由于捆绑显示名称为空,我没有收到任何相机权限警报。它阻止了视图的渲染


问题不在视图中,而是在未经许可的情况下显示。如果您的应用未列出,则可以在设置-->隐私-->摄像头上检查该问题。问题可能与此相同

我使用的是Phonegap,但在谷歌搜索错误消息时,此线程始终作为第一个线程出现

对我来说,通过将imagetype定义为PNG,解决了这个问题

encodingType : Camera.EncodingType.PNG
因此,整个路线是:

 navigator.camera.getPicture(successFunction, failFunction, { encodingType : Camera.EncodingType.PNG, correctOrientation:true, sourceType : Camera.PictureSourceType    .PHOTOLIBRARY, quality: 70, allowEdit : false , destinationType: Camera.DestinationType.DATA_URL});

您的里程数可能会有所不同,但这对我来说很有用。

调用此方法对我很有效。在呈现您的视图后放置它

[yourViewBeingPresented.view layoutIfNeeded];

我有一个UIAlertControllerStyleActionSheet,让用户可以选择用相机拍照或使用图书馆的照片

我在错误消息上尝试了一个符号断点

这向我表明,错误是在演示过程中实习生使用UICollectionView产生的

[self presentViewController:alert animated:YES completion:nil];

我修复了这个问题,在演示之前明确地设置了框架

[alert setPreferredContentSize: alert.view.frame.size];
下面是一个完整的方法,它可以在没有错误的情况下工作

-(void)showImageSourceAlertFromSender:(id)sender{
UIButton *senderButton = (UIButton*)sender;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"Camera" style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction *action) {
                                                         [self takePhoto];
                                                     }];
UIAlertAction *libraryAction = [UIAlertAction actionWithTitle:@"Library" style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
                                                          [self selectPhotoFromLibraryFromSender:sender];
                                                      }];
[alert addAction:cameraAction];
[alert addAction:libraryAction];
alert.popoverPresentationController.delegate = self;
alert.popoverPresentationController.sourceRect = senderButton.frame;
alert.popoverPresentationController.sourceView = self.view;

[alert setPreferredContentSize: alert.view.frame.size];

[self presentViewController:alert animated:YES completion:^(){
}];}
在显示视图控制器之前,可以通过引用
view
属性使“快照视图”警告静音。这样做会导致加载视图,并允许iOS在拍摄快照之前对其进行渲染

UIAlertController *controller = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
controller.modalPresentationStyle = UIModalPresentationPopover;
controller.popoverPresentationController.barButtonItem = (UIBarButtonItem *)sender;

... setup the UIAlertController ... 

[controller view]; // <--- Add to silence the warning.

[self presentViewController:controller animated:YES completion:nil];
UIAlertController*控制器=[UIAlertController alertControllerWithTitle:nil消息:nil首选样式:UIAlertControllerStyleActionSheet];
controller.modalPresentationStyle=UIModalPresentati