UIImagePickerController错误:在iOS 7中快照未呈现的视图会导致空快照

Did*_*adi 103 iphone camera uiimagepickercontroller ios ios7

我只在iOS 7中收到此错误并且应用程序崩溃了.在iOS 6中,我从未收到任何错误,只是在打开相机时出现内存警告.

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.
Run Code Online (Sandbox Code Playgroud)

这就是我在做的事情.

imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setAllowsEditing:YES];

[self presentModalViewController:imagePicker animated:YES];
Run Code Online (Sandbox Code Playgroud)

我确实试图延迟presentModalViewController,但我仍然得到相同的消息.几秒钟后(7-10),应用程序崩溃了.

此错误仅出现在iOS 7中.

有人有线索吗?先感谢您.

Lef*_*ris 32

iOS7中的问题与转换有关.似乎如果之前的转换没有完成并且您启动了一个新转换,iOS7会混淆视图,其中iOS6似乎正确地管理它.

UIViewController只有在视图已加载且超时后,才应在您的相机中初始化相机:

- (void)viewDidAppear:(BOOL)animated 
{
    [super viewDidAppear:animated];
    //show camera...
    if (!hasLoadedCamera)
        [self performSelector:@selector(showcamera) withObject:nil afterDelay:0.3];
}
Run Code Online (Sandbox Code Playgroud)

这是初始化代码

- (void)showcamera {
    imagePicker = [[UIImagePickerController alloc] init];
    [imagePicker setDelegate:self];
    [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
    [imagePicker setAllowsEditing:YES];

    [self presentModalViewController:imagePicker animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

  • iOS8同样的麻烦和修复. (5认同)
  • 在iOS 6中不推荐使用presentModalViewController.建议现在使用presentViewController. (3认同)
  • 我没有在viewDidAppear/Load中初始化相机.我有一个tableview,我提起相机以响应其中一个tableview选项.我收到此错误消息.有任何想法吗? (3认同)

Sco*_*ter 18

Apple的PhotoPicker示例代码项目也出现了这个错误.

我在iPhone 4上使用Xcode Version 5.0和iOS 7.0.3.

重现步骤:

  1. 通过https://developer.apple.com/library/ios/samplecode/PhotoPicker/Introduction/Intro.html下载Apple的PhotoPicker示例项目

  2. 在APLViewController.m中注释掉第125行

    //imagePickerController.showsCameraControls = NO;

  3. 在APLViewController.m中注释掉第130-133行

    //[[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil];
    // self.overlayView.frame = imagePickerController.cameraOverlayView.frame;
    // imagePickerController.cameraOverlayView = self.overlayView;
    // self.overlayView = nil;

  4. 构建并启动应用程序.

  5. 启动后,将设备旋转到横向模式.

  6. 单击"相机"图标以在"相机"模式下打开UIImagePickerController.

  7. 查看控制台输出.

控制台输出

PhotoPicker [240:60b]快照未渲染的视图会导致空快照.确保在屏幕更新后快照或快照之前至少渲染了一次视图.

showsCameraControls属性

当它的值为YES(默认值)时,会出现问题.

将此设置为NO会消除该消息.

错误报告

我刚刚向Apple提交了一份错误报告.

我尝试了很多在不同帖子中提出的建议,但没有找到令人满意的解决方法.


小智 11

当我试图在弹出窗口中显示摄像机视图时,我遇到了问题.在iOS6下这没问题,但在iOS7中我得到了消息

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.
Run Code Online (Sandbox Code Playgroud)

同样.

然而,在我将相机视图的显示更改为全屏后,如拍摄照片和电影中所述,iOS开发者库一切都恢复正常,消息再也没有出现.但是我必须确保取决于应用程序在哪种模式下(即,呈现相机视图或照片滚动),我必须- (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker在调用方法时关闭弹出窗口或视图控制器.

  • cameraUI.modalPresentationStyle = UIModalPresentationFullScreen; 适合我.这是唯一在这里取得成功的事情.谢谢! (3认同)
  • 最后!我多次遇到这个问题,从来没有找到一个好的解决方案.感觉如此愚蠢,因为从来没有在问题线程中进一步向下看 - imagePicker.modalPresentationStyle = UIModalPresentationFullScreen; 为我解决了这个问题.这应该是接受的答案:) (2认同)

Asf*_*nur 6

创建一个属性

@property (nonatomic) UIImagePickerController *imagePickerController;
Run Code Online (Sandbox Code Playgroud)

然后

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.modalPresentationStyle = UIModalPresentationCurrentContext;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing = YES;
self.imagePickerController = picker;
[self presentViewController:self.imagePickerController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

这应该可以解决问题

  • picker.modalPresentationStyle = UIModalPresentationCurrentContext; 为我带来了不同. (3认同)