博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IOS8后UIImagePickConroller警告提示解决方法
阅读量:4353 次
发布时间:2019-06-07

本文共 1902 字,大约阅读时间需要 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.

问题分析:iOS8在调用系统相机拍照时,会有一两秒的停顿,然后再弹出UIImagePickConroller,IOS7是没有这个问题的,在找了无数遍都没能解决这个问题,有说要将imagePickController设置为全局变量,有说要延时0.5秒再presentViewController的,各显神通,但很遗憾的都没能解决这个问题,今天特意单独写个Demo来研究此问题,终于取得了突破性的进展!
其实根本原因不在于系统拍照控制器上面,而是执行presentViewController这个动作本身!我们可以查看下UIViewController这个类,他有一个属性

@property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle NS_AVAILABLE_IOS(3_2);

这是一个枚举值,在iOS7的SDK中,定义如下:

typedef 
NS_ENUM
(
NSInteger
, UIModalPresentationStyle) {
    
UIModalPresentationFullScreen = 0,
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
    
UIModalPresentationPageSheet,
    
UIModalPresentationFormSheet,
    
UIModalPresentationCurrentContext,
#endif
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
    
UIModalPresentationCustom,
    
UIModalPresentationNone = -1,       
#endif       
};
 
 

在iOS8的SDK中定义如下:

typedef 
NS_ENUM
(
NSInteger
, UIModalPresentationStyle) {
        
UIModalPresentationFullScreen = 0,
        
UIModalPresentationPageSheet 
NS_ENUM_AVAILABLE_IOS
(3_2),
        
UIModalPresentationFormSheet 
NS_ENUM_AVAILABLE_IOS
(3_2),
        
UIModalPresentationCurrentContext 
NS_ENUM_AVAILABLE_IOS
(3_2),
        
UIModalPresentationCustom 
NS_ENUM_AVAILABLE_IOS
(7_0),
        
UIModalPresentationOverFullScreen 
NS_ENUM_AVAILABLE_IOS
(8_0),
        
UIModalPresentationOverCurrentContext 
NS_ENUM_AVAILABLE_IOS
(8_0),
        
UIModalPresentationPopover 
NS_ENUM_AVAILABLE_IOS
(8_0),
        
UIModalPresentationNone 
NS_ENUM_AVAILABLE_IOS
(7_0) = -1, 

解决问题的关键部分来了,IOS8多了一个样式UIModalPresentationOverCurrentContext,IOS8中presentViewController时请将控制器的modalPresentationStyle设置为UIModalPresentationOverCurrentContext,问题解决!!

if 
([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
    
self
.modalPresentationStyle=UIModalPresentationOverCurrentContext;
}
 

转载于:https://www.cnblogs.com/liwenxiao1987/p/4380236.html

你可能感兴趣的文章
UIView的常用属性
查看>>
Git push
查看>>
蓝桥杯基础练习题9(表达式)
查看>>
关于beescms如何去掉底部版权信息
查看>>
CodeForces - 13D Triangles
查看>>
面试题
查看>>
ELK简单使用
查看>>
Mysql 新建用户以及授权远程连接操作
查看>>
【Hive学习之五】Hive 参数&动态分区&分桶
查看>>
##DAY11 UITableView编辑
查看>>
为什么程序员都是夜猫子
查看>>
linux shell program summary
查看>>
流畅的python和cookbook学习笔记(二)
查看>>
【转】如何用WINDBG分析64位机上32位程序的DUMP文件
查看>>
C语言基础二维数组
查看>>
select函数
查看>>
Android中的调试
查看>>
C++ 用RGB 三种颜色绘图
查看>>
memcache和memcached的区别
查看>>
[置顶] 处世悬镜之舍之
查看>>