{"id":381,"date":"2015-03-09T14:29:38","date_gmt":"2015-03-09T06:29:38","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=381"},"modified":"2016-07-14T14:37:01","modified_gmt":"2016-07-14T06:37:01","slug":"snapshotting-a-view-that-has-not-been-rendered-results-in-an-empty-snapshot","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/analysis\/2015\/03\/09\/142938381.html","title":{"rendered":"Snapshotting a view that has not been rendered results in an empty snapshot. &#8230;"},"content":{"rendered":"<p><strong>\u9519\u8bef\u4ee3\u7801\uff1a<\/strong>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.<\/p>\n<p>\u95ee\u9898\u5206\u6790\uff1aiOS8\u5728\u8c03\u7528\u7cfb\u7edf\u76f8\u673a\u62cd\u7167\u65f6\uff0c\u4f1a\u6709\u4e00\u4e24\u79d2\u7684\u505c\u987f\uff0c\u7136\u540e\u518d\u5f39\u51faUIImagePickConroller\uff0cIOS7\u662f\u6ca1\u6709\u8fd9\u4e2a\u95ee\u9898\u7684\uff0c\u5728\u767e\u5ea6\u627e\u4e86\u65e0\u6570\u904d\u90fd\u6ca1\u80fd\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6709\u8bf4\u8981\u5c06imagePickController\u8bbe\u7f6e\u4e3a\u5168\u5c40\u53d8\u91cf\uff0c\u6709\u8bf4\u8981\u5ef6\u65f60.5\u79d2\u518dpresentViewController\u7684\uff0c\u5404\u663e\u795e\u901a\uff0c\u4f46\u5f88\u9057\u61be\u7684\u90fd\u6ca1\u80fd\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4eca\u5929\u7279\u610f\u5355\u72ec\u5199\u4e2aDemo\u6765\u7814\u7a76\u6b64\u95ee\u9898\uff0c\u7ec8\u4e8e\u53d6\u5f97\u4e86\u7a81\u7834\u6027\u7684\u8fdb\u5c55\uff01<\/p>\n<p>\u5176\u5b9e\u6839\u672c\u539f\u56e0\u4e0d\u5728\u4e8e\u7cfb\u7edf\u62cd\u7167\u63a7\u5236\u5668\u4e0a\u9762\uff0c\u800c\u662f\u6267\u884cpresentViewController\u8fd9\u4e2a\u52a8\u4f5c\u672c\u8eab\uff01\u6211\u4eec\u53ef\u4ee5\u67e5\u770b\u4e0bUIViewController\u8fd9\u4e2a\u7c7b\uff0c\u4ed6\u6709\u4e00\u4e2a\u5c5e\u6027<\/p>\n<pre lang=\"objc\" line=\"1\">@property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle NS_AVAILABLE_IOS(3_2);<\/pre>\n<p><!--more--><br \/>\n\u8fd9\u662f\u4e00\u4e2a\u679a\u4e3e\u503c\uff0c\u5728iOS7\u7684SDK\u4e2d\uff0c\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n<pre lang=\"objc\" line=\"1\">typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {\n    UIModalPresentationFullScreen = 0,\n#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2\n    UIModalPresentationPageSheet,\n    UIModalPresentationFormSheet,\n    UIModalPresentationCurrentContext,\n#endif\n#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0\n    UIModalPresentationCustom,\n    UIModalPresentationNone = -1,        \n#endif        \n};<\/pre>\n<p>\u5728iOS8\u7684SDK\u4e2d\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n<pre lang=\"objc\" line=\"1\">typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {\n        UIModalPresentationFullScreen = 0,\n        UIModalPresentationPageSheet NS_ENUM_AVAILABLE_IOS(3_2),\n        UIModalPresentationFormSheet NS_ENUM_AVAILABLE_IOS(3_2),\n        UIModalPresentationCurrentContext NS_ENUM_AVAILABLE_IOS(3_2),\n        UIModalPresentationCustom NS_ENUM_AVAILABLE_IOS(7_0),\n        UIModalPresentationOverFullScreen NS_ENUM_AVAILABLE_IOS(8_0),\n        UIModalPresentationOverCurrentContext NS_ENUM_AVAILABLE_IOS(8_0),\n        UIModalPresentationPopover NS_ENUM_AVAILABLE_IOS(8_0),\n        UIModalPresentationNone NS_ENUM_AVAILABLE_IOS(7_0) = -1,         \n};<\/pre>\n<p>\u89e3\u51b3\u95ee\u9898\u7684\u5173\u952e\u90e8\u5206\u6765\u4e86\uff0cIOS8\u591a\u4e86\u4e00\u4e2a\u6837\u5f0fUIModalPresentationOverCurrentContext\uff0cIOS8\u4e2dpresentViewController\u65f6\u8bf7\u5c06\u63a7\u5236\u5668\u7684modalPresentationStyle\u8bbe\u7f6e\u4e3aUIModalPresentationOverCurrentContext\uff0c\u95ee\u9898\u89e3\u51b3\uff01\uff01<\/p>\n<pre lang=\"objc\" line=\"1\">if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {\n    self.modalPresentationStyle=UIModalPresentationOverCurrentContext;\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9519\u8bef\u4ee3\u7801\uff1aSnapshotting 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. \u95ee\u9898\u5206\u6790\uff1aiOS8\u5728\u8c03\u7528\u7cfb\u7edf\u76f8\u673a\u62cd\u7167\u65f6\uff0c\u4f1a\u6709\u4e00\u4e24\u79d2\u7684\u505c\u987f\uff0c\u7136\u540e\u518d\u5f39\u51faUIImagePickConroller\uff0cIOS7\u662f\u6ca1\u6709\u8fd9\u4e2a\u95ee\u9898\u7684\uff0c\u5728\u767e\u5ea6\u627e\u4e86\u65e0\u6570\u904d\u90fd\u6ca1\u80fd\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6709\u8bf4\u8981\u5c06imagePickController\u8bbe\u7f6e\u4e3a\u5168\u5c40\u53d8\u91cf\uff0c\u6709\u8bf4\u8981\u5ef6\u65f60.5\u79d2\u518dpresentViewController\u7684\uff0c\u5404\u663e\u795e\u901a\uff0c\u4f46\u5f88\u9057\u61be\u7684\u90fd\u6ca1\u80fd\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4eca\u5929\u7279\u610f\u5355\u72ec\u5199\u4e2aDemo\u6765\u7814\u7a76\u6b64\u95ee\u9898\uff0c\u7ec8\u4e8e\u53d6\u5f97\u4e86\u7a81\u7834\u6027\u7684\u8fdb\u5c55\uff01 \u5176\u5b9e\u6839\u672c\u539f\u56e0\u4e0d\u5728\u4e8e\u7cfb\u7edf\u62cd\u7167\u63a7\u5236\u5668\u4e0a\u9762\uff0c\u800c\u662f\u6267\u884cpresentViewController\u8fd9\u4e2a\u52a8\u4f5c\u672c\u8eab\uff01\u6211\u4eec\u53ef\u4ee5\u67e5\u770b\u4e0bUIViewController\u8fd9\u4e2a\u7c7b\uff0c\u4ed6\u6709\u4e00\u4e2a\u5c5e\u6027 @property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle NS_AVAILABLE_IOS(3_2);<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-381","post","type-post","status-publish","format-standard","hentry","category-analysis"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=381"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/381\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}