ios8 statusBar hidden and show
来源:互联网 发布:学编程学费要多少钱 编辑:程序博客网 时间:2024/06/02 04:55
iOS8 statusBar hidden and show
写博客的原因:
从iOS7开始到iOS9,代码中一共不下6次用到,每次都要从网上搜好半天,但是依然不得要领,每次都要重复造车轮,相对来说,自己写一篇详细的笔记,以后使用可能会更方便。
三石的博客上解释的很明确,statusBar的显示与隐藏,从思路着手,我们首先应该想到UIViewController、UINavgationController、UIWindow、UIApplication 这几个类,之后查看这些类的API,看看有没有相关的方法,然后进行尝试。
需求 全局隐藏statusBar
查看UIApplication的API
// Setting the statusBarStyle does nothing if your application is using the default UIViewController-based status bar system. @property(readwrite, nonatomic) UIStatusBarStyle statusBarStyle NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]"); - (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated NS_DEPRECATED_IOS(2_0, 9_0, "Use - [UIViewController preferredStatusBarStyle]"); // Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system. @property(readwrite, nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden NS_DEPRECATED_IOS(2_0, 9_0, "Use - [UIViewController prefersStatusBarHidden]"); - (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation NS_DEPRECATED_IOS(3_2, 9_0, "Use - [UIViewController prefersStatusBarHidden]");
通过阅读注释// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.
查找 UIViewController-based status bar system.设置地方,可知需要在plist文件中设置 ,测试,statusBar成功影藏请使用含有一个viewCOntroller的项目进行测试,防止其他地方干扰
需求增加 设定某个viewController statusBarShow且content 为白色
设定 plist文件中 UIViewController-based status bar system = YES;
设定 [[UIApplication sharedApplication] setStatusBarHidden:NO];
查看UIViewController API
// These methods control the attributes of the status bar when this view controller is shown. They can be overridden in view controller subclasses to return the desired status bar attributes.- (UIStatusBarStyle)preferredStatusBarStyle NS_AVAILABLE_IOS(7_0); // Defaults to UIStatusBarStyleDefault- (BOOL)prefersStatusBarHidden NS_AVAILABLE_IOS(7_0); // Defaults to NO// Override to return the type of animation that should be used for status bar changes for this view controller. This currently only affects changes to prefersStatusBarHidden.- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation NS_AVAILABLE_IOS(7_0); // Defaults to UIStatusBarAnimationFade// This should be called whenever the return values for the view controller's status bar attributes have changed. If it is called from within an animation block, the changes will be animated along with the rest of the animation block.- (void)setNeedsStatusBarAppearanceUpdate NS_AVAILABLE_IOS(7_0);
仔细阅读API及注释发现,ViewController 可以自己设定特定的statusBarStyle 及hidden show 测试发现ok
引入到工程中发现statusBarStyle没有实现
貌似中间漏掉了什么,对,UINavigationController,xcode6.4之前建立的项目,要设置UINavigationController的NavgationBar的barStyle为黑白,才能实现,正如苹果API所说:
UIStatusBarStyleDefault = 0, // Dark content, for use on light backgrounds
UIStatusBarStyleLightContent NS_ENUM_AVAILABLE_IOS(7_0) = 1, // Light content, for use on dark backgrounds
实现的时候发现个问题:
屏幕开始时,statusBar由黑色变为白色,中间有个变化的过程,通过修改infoPlist中的Status bar style 为Transparent black style (alpha of 0.5),变化消失
发现问题,先通过查找苹果的API,检查实现是否遵循苹果的要求,不要一味的查网上的资源
- ios8 statusBar hidden and show
- how to show hidden parameter
- angularjs ng-show ng-hidden
- observe keyboard show or hidden
- iOS8修改状态栏StatusBar字体颜色
- ios8 push无缝隐藏navibar和statusbar
- hide and appear of statusbar
- show() and showDialog()
- Fragment Hide and Show
- Hidden terminal and Exposed terminal
- jquery 利用show和hidden实现级联菜单
- How to show hidden files in ubuntu(linux) :)
- Fragment hide/show 切换 走的方法onHiddenChanged(boolean hidden)
- StatusBar
- statusbar
- StatusBar
- statusBar
- StatusBar
- iOS安全系列之一:HTTPS
- 手机号码中间四位星号表示实例代码
- Edit Distance
- 网络扫描技术揭秘
- 黑马程序员——Java基础---多线程
- ios8 statusBar hidden and show
- 数据库分库分表-水平分表笔记
- 端上保证可靠性还是链路保证
- java.lang.IllegalStateException: Could not find a method onStartSingleInstanceActivityClickLisenter(
- Android实战简易教程<五十九>(EventBus小实例-传值、控制其他页控件显示)
- Test Automation Tools
- hadoop小文件问题&解决方案
- 设计模式 适配器模式 以手机充电器为例
- Google I/O 2014 & 2015 之 ART