ios8調用相機報警告: Snapshotting a view that has not been rendered results in an empty snapshot. Ensure yo

轉載自:  http://bbs.yusian.com/thread-10352-1-1.html


我這也報了這個警告,但按他的方法並沒有起作用,把寫到這個地方看是否其他人用的到


錯誤代碼: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這個類,他有一個屬性

[Objective-C] 純文本查看 複製代碼
@property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle NS_AVAILABLE_IOS(3_2);
這是一個枚舉值,在iOS7的SDK中,定義如下:
[Objective-C] 純文本查看 複製代碼
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中定義如下:
[Objective-C] 純文本查看 複製代碼
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,問題解決!!
[Objective-C] 純文本查看 複製代碼
if([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
    self.modalPresentationStyle=UIModalPresentationOverCurrentContext;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章