您的位置:首页 > 产品设计 > UI/UE

iPad使用相机中的一个坑(UIModalPresentationStyle,UIStatusBar)

2018-03-29 15:56 399 查看
今天解决了一个相机相关的bug,感觉有些人可能也会遇到,就说一下吧。

问题是这样子的,我们应用在用户信息页面,需要支持更换头像,这里需要能够直接从相机获取,同样的代码,在iPhone上没有任何问题,切换到iPad以后,发现照相页面总是会出现
statusBar
,无论是重写
prefersStatusBarHidden
函数还是通过
[[UIApplication sharedApplication] setStatusBarHidden:YES]
进行设置都不生效,具体的现象可以看下图:

现象.jpg

后来各种查文档,找资料,才发现是由于用户信息页面是通过
UIModalPresentationStyleFormSheet
方式
present
导致的问题,这样
present
出来的页面对
statusBar
的设置都是无效的。必须设置
controller
modalPresentationCapturesStatusBarAppearance
属性才可以。

设置以后,新的页面对
statusBar
的设置才会有效。

When you present a view controller by calling the present(_:animated:completion:)
method, status bar appearance control is transferred from the presenting to the presented view controller only if the presented controller'��s modalPresentationStyle
value is fullScreen
. By setting this property to true
, you specify the presented view controller controls status bar appearance, even though presented non-fullscreen.

The system ignores this property’s value for a view controller presented fullscreen.

文档中描述了,默认只有全屏模式的
presentedController
才会转换
statusBar
的控制权,否则
statusBar
仍旧由前一个页面控制。如果想要
present
一个非全屏的页面,又要控制
statusBar
,那么就要把这个属性设置为
true


苹果的开发文档中对这个属性已经做了描述,但却由于不经常使用被我和同时都给忽略了,才会出现这样的问题,希望我们读文档时能够细心一点,避免再次出现这样的问题。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: