UIImagePickerController 错误:对尚未渲染的视图进行快照会导致 iOS 7 中的快照为空 [英] UIImagePickerController error: Snapshotting a view that has not been rendered results in an empty snapshot in iOS 7

查看:12
本文介绍了UIImagePickerController 错误:对尚未渲染的视图进行快照会导致 iOS 7 中的快照为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am getting this error only in iOS 7 and the application crashed. In iOS 6, I never get any error, just once of memory warning when opening the camera.

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.

这就是我正在做的事情.

Here is what I am doing.

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

[self presentModalViewController:imagePicker animated:YES];

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

I did tried to delay the presentModalViewController, but I am still getting the same message. After few seconds (7-10), the application crashed.

此错误仅出现在 iOS 7 中.

This error is only present in iOS 7.

有人知道吗?

推荐答案

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

The problem in iOS7 has to do with transitions. It seems that if a previous transition didn't complete and you launch a new one, iOS7 messes the views, where iOS6 seems to manage it correctly.

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

You should initialize your Camera in your UIViewController, only after the view has Loaded and with a timeout:

- (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];
}

这篇关于UIImagePickerController 错误:对尚未渲染的视图进行快照会导致 iOS 7 中的快照为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆