转自:http://blog.csdn.net/dqjyong/article/details/17896145

IOS7中,不仅应用的风格有一定的变化,状态栏变化比较大,我们可以看到UIVIEWCONTROLLER的状态栏与导航栏基本是一体的。因此UIVIEWCONTROLLER的HIDE/SHOW状态的方法也跟其他版本的不一样了。 在IOS7以前的版本,HIDE/SHOW是通过以下代码实现

  1. [[UIApplication sharedApplication] setStatusBarHidden:YES(NO) withAnimation:UIStatusBarAnimationSlide];

在iOS7中默认情况下,这个方法不成功了。到setStatusBarHidden:withAnimation:声明的头文件去看看,多了一句注释: // Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system. 现在在iOS7中,status bar的外观默认依赖UIViewController, 也就是说status bar随UIViewController的不同而不同。在这种默认的方式下,用全局的方法setStatusBarHidden:withAnimation:是行不通的。

google一下发现现在的解决方法有两种:

如果只是单纯的隐藏状态栏,那么是在默认情况下,只需要重新实现两个新方法

  1. - (UIStatusBarStyle)preferredStatusBarStyle
  2. {
  3. return UIStatusBarStyleLightContent;
  4. //UIStatusBarStyleDefault = 0 黑色文字,浅色背景时使用
  5. //UIStatusBarStyleLightContent = 1 白色文字,深色背景时使用
  6. }
  7. - (BOOL)prefersStatusBarHidden
  8. {
  9. return NO; //返回NO表示要显示,返回YES将hiden
  10. }

上面一个回调方法返回status bar显示时候的样式,下面一个回调控制是否显示status bar.

调用下面的一行代码将会触发上面的回调

  1. [self setNeedsStatusBarAppearanceUpdate];

如果想在hiden/show之间有点动画效果,用下面的代码即可:

  1. [UIView animateWithDuration:0.5 animations:^{
  2. [self setNeedsStatusBarAppearanceUpdate];
  3. }];

或者调用下面的代码:

  1. [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];

还有一种方法是在infor.plist中加入key:UIViewControllerBasedStatusBarAppearance 并设置其值为NO,这样就告诉系统,status bar不依赖于UIViewController. 这样就可以通过上面的方法来hiden status bar.

在设置好这些,我们还是会发现一些问题,就是状态栏虽然没有了,但取而代之的是黑色的一片区域,所以我们还需要调整UIViewController的视图,具体代码为:

  1. -(void)viewDidLayoutSubviews
  2. {
  3. CGRect viewBounds = self.view.bounds;
  4. CGFloat topBarOffset = 20.0;
  5. viewBounds.origin.y = -topBarOffset;
  6. self.view.bounds = viewBounds;
  7. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];//for status bar style
  8. }

iOS7隐藏状态栏 status Bar的更多相关文章

  1. iOS7隐藏状态栏 statusBar

    转:http://blog.csdn.net/dqjyong/article/details/17896145 评:通过这点变化,可以看出苹果倾向于使用delegate取代全局变量. IOS7中,不仅 ...

  2. 如何彻底隐藏iOS7应用的status bar

    用xcode5开发新的iOS游戏,发现一个坑爹的现象,虽然我已经在info.plist里面把Status bar is initially hidden设置成了YES,但在设备上一跑还是看到丑陋的st ...

  3. IOS7 隐藏状态栏 (电池栏)

    电池状态栏. //方法一(代码设置): 现在ios7已经更改为透明,并且不占用屏幕高度.其中隐藏及显示的方法如下: 在uiviewcontroller的子类下,调用:     if ([self re ...

  4. [Android] 获取系统顶部状态栏(Status Bar)与底部导航栏(Navigation Bar)的高度

    Android一些设备都有上下两条bar,我们可以获取这些bar的信息.下面放上获取高度的代码.代码注释和其他方法有空再放. 原文地址请保留http://www.cnblogs.com/rossone ...

  5. IOS7 隐藏状态栏

    - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } // - (BOOL)pref ...

  6. iOS7 隐藏状态栏 hide statusBar

    1.调用 [self setNeedsStatusBarAppearanceUpdate]; 2.重载以下函数 - (BOOL)prefersStatusBarHidden{ return _hide ...

  7. iOS 使用Method Swizzling隐藏Status Bar

    在iOS 6中,隐藏Status Bar很的简单. // iOS 6及曾经,隐藏状态栏 [[UIApplication sharedApplication] setStatusBarHidden:YE ...

  8. iOS6和iOS7代码的适配(2)——status bar

    用Xcode5运行一下应用,第一个看到的就是status bar的变化.在iOS6中,status bar是系统在处理,应用中不需要考虑这部分,iOS7之后是应用在处理,每个ViewControlle ...

  9. iOS7下status bar相关问题的解决方法

    转载自:http://blog.csdn.net/volcan1987/article/details/14227313 iOS7里status bar的实现跟iOS6下有写不一样,前段时间碰到了这个 ...

随机推荐

  1. 基于py3和pymysql查询某时间段的数据

    #python3 #xiaodeng #基于py3和pymysql查询某时间段的数据 import pymysql conn=pymysql.connect(user='root',passwd='r ...

  2. nginx 代理静态资源报 403

    用tomcat跑了一个上传服务,文件上传到指定nginx的html目录,用nginx来代理静态资源,结果上传能够成功,访问却报403. 解决办法,将html的拥有者改成nobody: chown -R ...

  3. spring boot mybatis没有扫描jar中的Mapper接口

    只需要在spring boot启动类上加上注解,并指定jar包中接口文件包路径即可 如下: @ComponentScan(basePackages = "com.xx") @Map ...

  4. A. Kyoya and Photobooks(Codeforces Round #309 (Div. 2))

    A. Kyoya and Photobooks   Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ...

  5. libgdx游戏引擎教程

    第一讲:libgdx游戏引擎教程(一)性能优良的游戏引擎—libgdx http://www.apkbus.com/android-57355-1-1.html 第二讲: libgdx游戏引擎教程(二 ...

  6. postmessage and sendmessage

    从msdn上看二者的解释: postmessage : Places (posts) a message in the message queue associated with the thread ...

  7. MySQL的keepalived高可用监控脚本

    MySQL的keepalived高可用监控脚本 MySQL(或者其它服务)的keepalived高可用监控脚本 开发脚本需求 :我们知道,keepalive是基于虚拟ip的存活来判断是否抢占maste ...

  8. POJ 2676 Sudoku (DFS)

    Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11694   Accepted: 5812   Special ...

  9. React(0.13) hello world

    <!DOCTYPE html> <html> <head> <title>React JS</title> <script src=& ...

  10. 如何禁用Visual Studio 2013的浏览器链接功能

    VS2013新增的Browser Link功能虽然“强大”,但我并不需要. 但默认是开启的,会在页面中自动添加如下的代码,真是烦人! <!-- Visual Studio Browser Lin ...