我只在iOS 7中遇到这个错误,应用程序崩溃了.

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.

这就是我正在做的事情.

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

[self presentModalViewController:imagePicker animated:YES];

我确实试着推迟了presentModalViewController次,但我还是收到了同样的信息.几秒钟(7-10)后,应用程序崩溃.

此错误仅在iOS 7中存在.

有谁有线索吗?

推荐答案

iOS7中的问题与转换有关.如果之前的转换没有完成,而你又启动了一个新的转换,那么iOS7会扰乱视图,而iOS6似乎可以正确地管理视图.

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

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

下面是初始化代码

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

    [self presentModalViewController:imagePicker animated:YES];
}

Ios相关问答推荐

SwiftUI中ForEach和@ State数组的可能并发问题

如何在SWIFT中处理不可发送的类型?

SWIFT设备方向更新不正确

创建带有Flutter 翼的会所头像

如何在SwiftUI中为带有CornerRadius的矩形创建下边框?

IOS-获取本地化系统映像

如何删除NavigationView中的默认透明标头?

如何使用Swift以编程方式更改SVG文件中某些元素的 colored颜色

在最新版本的 iOS 中,设备上的Localized.strings文件发生了什么变化?

归档时命令 PhaseScriptExecution 失败,退出代码非零

SwiftUI 每秒从 Timer 更新单个 @State 属性,每秒也重绘整个视图

发生异常:需要 issuerId

在 Swift 中映射 MySQL 数据

Xcode 14 需要为 Pod Bundles Select 开发团队

如何用 Swift 圆化 UILabel 的边缘

Select 器touchesBegan:withEvent:的覆盖方法具有不兼容的类型(NSSet,UIEvent)->()

文件是为存档而构建的,它不是被链接的体系 struct (i386)

AVAudioRecorder 抛出错误

如何在 iOS 中获取正在运行的应用程序的名称

Twitter api 文本字段值被截断