Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has be

本文解决了iOS8系统相机拍照时出现的一两秒停顿问题。通过调整presentViewController的modalPresentationStyle为UIModalPresentationOverCurrentContext,可以有效避免延迟现象。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://bbs.yusian.com/thread-10352-1-1.html 原文地址


问题分析: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] 纯文本查看 复制代码
typedef NS_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] 纯文本查看 复制代码
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
        UIModalPresentationFullScreen = 0,
        UIModalPresentationPageSheet NS_ENUM_AVAILABLE_IOS(3_2),
        UIModalPresentationFormSheet NS_ENUM_AVAILABLE_IOS(3_2),
        UIModalPresentationCurrentContext NS_ENUM_AVAILABLE_IOS(3_2),
        UIModalPresentationCustom NS_ENUM_AVAILABLE_IOS(7_0),
        UIModalPresentationOverFullScreen NS_ENUM_AVAILABLE_IOS(8_0),
        UIModalPresentationOverCurrentContext NS_ENUM_AVAILABLE_IOS(8_0),
        UIModalPresentationPopover NS_ENUM_AVAILABLE_IOS(8_0),
        UIModalPresentationNone NS_ENUM_AVAILABLE_IOS(7_0) = -1,        
};
解决问题的关键部分来了,IOS8多了一个样式UIModalPresentationOverCurrentContext,IOS8中presentViewController时请将控制器的modalPresentationStyle设置为UIModalPresentationOverCurrentContext,问题解决!!
[Objective-C] 纯文本查看 复制代码
if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
    self.modalPresentationStyle=UIModalPresentationOverCurrentContext;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值