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

2025-05-29 0 20

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

错误代码: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这个类,他有一个属性:

?

1

2
@property(nonatomic,assign)

UIModalPresentationStyle modalPresentationStyle NS_AVAILABLE_IOS(3_2);

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

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

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

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24
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,问题解决!!

?

1

2

3

4

5

6
if([[[UIDevice

currentDevice] systemVersion] floatValue]>=8.0) {

self.modalPresentationStyle=UIModalPresentationOverCurrentContext;

}

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

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 iOS8调用相机报警告Snapshotting a view的解决方法 https://www.kuaiidc.com/91799.html

相关文章

发表评论
暂无评论