当前位置: 移动技术网 > IT编程>移动开发>IOS > iOS8调用相机报警告Snapshotting a view的解决方法

iOS8调用相机报警告Snapshotting a view的解决方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

南宋红颜,游戏 外挂,中国神器爆米花机走红

因为我这也报了这个警告,所以把解决方法写到这个地方看是否其他人用的到,具体解决方法:

错误代码: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中,定义如下:

typedefns_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中定义如下:

typedefns_enum(nsinteger,
 uimodalpresentationstyle) {

    uimodalpresentationfullscreen
 = 0,

    uimodalpresentationpagesheetns_enum_available_ios(3_2),

    uimodalpresentationformsheetns_enum_available_ios(3_2),

    uimodalpresentationcurrentcontextns_enum_available_ios(3_2),

    uimodalpresentationcustomns_enum_available_ios(7_0),

    uimodalpresentationoverfullscreenns_enum_available_ios(8_0),

    uimodalpresentationovercurrentcontextns_enum_available_ios(8_0),

    uimodalpresentationpopoverns_enum_available_ios(8_0),

    uimodalpresentationnonens_enum_available_ios(7_0)
 = -1,     

};

解决问题的关键部分来了,ios8多了一个样式uimodalpresentationovercurrentcontext,ios8中presentviewcontroller时请将控制器的modalpresentationstyle设置为uimodalpresentationovercurrentcontext,问题解决!!

if([[[uidevice
 currentdevice] systemversion] floatvalue]>=8.0) {

  self.modalpresentationstyle=uimodalpresentationovercurrentcontext;

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网