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

查看:18
本文介绍了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天全站免登陆