iOS8调用相机报警告Snapshottingaview的解决方法
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
iOS8调⽤相机报警告Snapshottingaview的解决⽅法
因为我这也报了这个警告,所以把解决⽅法写到这个地⽅看是否其他⼈⽤的到,具体解决⽅法:
错误代码: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;
}
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。