iPad使用相机中的一个坑(UIModalPresentationStyle,UIStatusBar)
2018-03-29 15:56
399 查看
今天解决了一个相机相关的bug,感觉有些人可能也会遇到,就说一下吧。
问题是这样子的,我们应用在用户信息页面,需要支持更换头像,这里需要能够直接从相机获取,同样的代码,在iPhone上没有任何问题,切换到iPad以后,发现照相页面总是会出现
现象.jpg
后来各种查文档,找资料,才发现是由于用户信息页面是通过
设置以后,新的页面对
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.
文档中描述了,默认只有全屏模式的
苹果的开发文档中对这个属性已经做了描述,但却由于不经常使用被我和同时都给忽略了,才会出现这样的问题,希望我们读文档时能够细心一点,避免再次出现这样的问题。
问题是这样子的,我们应用在用户信息页面,需要支持更换头像,这里需要能够直接从相机获取,同样的代码,在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。
苹果的开发文档中对这个属性已经做了描述,但却由于不经常使用被我和同时都给忽略了,才会出现这样的问题,希望我们读文档时能够细心一点,避免再次出现这样的问题。
相关文章推荐
- IPhone开发 IPad使用UIModalPresentationFormSheet时隐藏键盘
- iPad keyboard will not dismiss if modal view controller presentation style is UIModalPresentationFor
- IPad使用UIModalPresentationFormSheet时隐藏键盘
- AWAY3D4BETA版在ipad移动设备上无法使用手指触发某一个3d对象的解决方案
- QSS使用setStyleSheet需要注意一个部件一个setStyleSheet
- testVC.modalPresentationStyle = UIModalPresentationFormSheet; 更改 VC大小
- UIModalPresentationStyle和UIModalTransitionStyle
- What is difference between UIModalTransitionStyle and UIModalPresentationStyle ?
- UIModalPresentationStyle和UIModalTransitionStyle
- Ipad项目中用到的UIModalPresentationFormSheet,点击阴影部分dismiss 当前presented的controller
- [转]UIModalPresentationStyle和UIModalTransitionStyle
- UIModalPresentationStyle和UIModalTransitionStyle
- IOS开发之小实例--使用UIImagePickerController创建一个简单的相机应用程序
- UIModalPresentationStyle即viewcontroller的显示方式
- presentModalViewController使用 UIModalPresentationFormSheet,无法改变frame大小
- iOS ipad开发 UIModalPresentationFormSheet模式的VC 无法关闭键盘解决方法
- iPad UIModalPresentationFormSheet 键盘不隐藏
- UIModalPresentationStyle和UIModalTransitionStyle
- presentModalViewController使用 UIModalPresentationFormSheet,无法改变frame大小
- StudioStyle 使用 厌倦了默认的Visutal Studio样式了,到这里找一个酷的试试