首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UIImagePickerController错误:快照尚未在iOS 7中呈现为空快照的视图

UIImagePickerController错误:快照尚未在iOS 7中呈现为空快照的视图
EN

Stack Overflow用户
提问于 2013-09-19 08:42:44
回答 16查看 67.9K关注 0票数 103

我只在iOS 7中得到这个错误,应用程序崩溃了。在iOS 6中,我从未收到任何错误,打开相机时只收到一次内存警告。

代码语言:javascript
运行
复制
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.

这就是我在做的事情。

代码语言:javascript
运行
复制
imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setAllowsEditing:YES];

[self presentModalViewController:imagePicker animated:YES];

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

此错误仅存在于iOS 7中。

有人知道线索吗?

EN

回答 16

Stack Overflow用户

回答已采纳

发布于 2013-10-14 10:04:10

iOS7中的问题与转换有关。看起来,如果之前的转换没有完成,并且启动了一个新的转换,iOS7就会破坏视图,而iOS6似乎会正确地管理它。

您应该在UIViewController中初始化相机,只有在视图加载并具有超时之后:

代码语言:javascript
运行
复制
- (void)viewDidAppear:(BOOL)animated 
{
    [super viewDidAppear:animated];
    //show camera...
    if (!hasLoadedCamera)
        [self performSelector:@selector(showcamera) withObject:nil afterDelay:0.3];
}

这是初始化代码

代码语言:javascript
运行
复制
- (void)showcamera {
    imagePicker = [[UIImagePickerController alloc] init];
    [imagePicker setDelegate:self];
    [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
    [imagePicker setAllowsEditing:YES];

    [self presentModalViewController:imagePicker animated:YES];
}
票数 32
EN

Stack Overflow用户

发布于 2013-11-02 15:05:48

这个错误也出现在苹果的PhotoPicker示例代码项目中。

我在iOS 4上使用了Xcode版本5.0和iPhone 7.0.3。

复制步骤:

  1. 在PhotoPicker下载苹果的https://developer.apple.com/library/ios/samplecode/PhotoPicker/Introduction/Intro.html示例项目
  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. 查看控制台输出。

控制台输出

PhotoPicker240:60b对未呈现视图的快照进行快照,结果为空快照。确保在快照或屏幕更新后的快照之前至少呈现过一次视图。

showsCameraControls property

当这个值为YES (默认值)时,就会出现问题。

将此设置为“否”可消除此消息。

Bug报告

我刚向苹果提交了一份窃听器报告。

我尝试过在不同岗位上提出的许多建议,但没有找到令人满意的解决办法。

票数 18
EN

Stack Overflow用户

发布于 2013-10-23 17:53:31

当我试图在弹出框内呈现相机视图时,我遇到了这个问题。在iOS6下,这没什么问题,但在iOS7中,我得到了消息

代码语言:javascript
运行
复制
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.

也是。

然而,在我将相机视图的显示方式更改为全屏(如拍摄图片和电影,iOS开发者库中所描述的)之后,一切又变得很好,并且消息再也没有出现。然而,我必须确保,根据应用程序的模式(例如,呈现相机视图或照片卷),无论何时调用- (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker方法,我都必须关闭弹出窗口或视图控制器。

票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18890003

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档