zoukankan      html  css  js  c++  java
  • iOS开发中如何隐藏各种bar

    状态条Status Bar

    [UIApplication sharedApplication].statusBarHidden = YES;

    或者
    // iOS3.2+支持

    [application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];

     statusBarHidden属性支持在iOS2.0+setStatusBarHidden:animated:方法在iOS3.2中开始取消了,而采用了setStatusBarHidden:withAnimation:方法。

    上述方法只能实现在程序跳过loading(即启动画面)的时候才能隐藏状态栏。如果想要在启动画面开始即隐藏状态栏,则要修改appinfo.plist文件,新增UIStatusBarHidden键(Status bar is initially hidden),其值是YES

    同理:对于状态栏的颜色改变,也要分别从两处着手,代码[[UIApplicationsharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];仅仅改变了启动画面之后的视图上的状态栏,要让App应用在启动画面之时就改变默认颜色,则要修改info.plist文件,新增UIStatusBarStyle键(Status bar style),其值有Opaque black styleTransparent black style和默认的Gray style

     

    导航条Navigation Bar

    [self.navigationController setNavigationBarHidden:YES];

    选项卡TabBar

    方法一:

    [self.tabBarController.tabBar setHidden:YES];

    此方法的问题:虽然tabBar栏被隐藏了,但该区域成一片空白区,无法被其他视图使用。

    方法二:
    对于navigationController+tabBarController的结构,可以在push下一级的childController之前将childControllerhidesBottomBarWhenPushed属性设为YES。比如,可以在childController的初始化方法中做这件事,代码如下:

     

    1 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 

    2

    3      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 

    4      if (self) { 

    5         // Custom initialization.

    6         self.hidesBottomBarWhenPushed = YES;

    7     } 

    8 return self;

    9 }

     

    方法三:

    View Code

    时机

     

     1 - (void)viewWillAppear:(BOOL)animated 

     2 {

     3      [self setFullScreen:YES];

     4

     5 - (void)viewWillDisappear:(BOOL)animated

     6  {

     7      [self setFullScreen:NO];

     8  } 

     9  - (void)setFullScreen:(BOOL)fullScreen 

    10 {

    11     // 状态条

    12      [UIApplication sharedApplication].statusBarHidden = fullScreen;

    13      // 导航条

    14     [self.navigationController setNavigationBarHidden:fullScreen];

    15      // tabBar的隐藏通过在初始化方法中设置hidesBottomBarWhenPushed属性来实现

    16  }

     

  • 相关阅读:
    【转】IBatis.Net项目数据库SqlServer迁移至Oracle
    【转】远程桌面 剪切板复制文件失效解决方法
    为什么越学反而越蠢?碎片化学习是个骗局
    Spring MVC起步
    [1-1] 把时间当做朋友(李笑来)Chapter 1 【心智的力量】 摘录
    Java反射总结
    No enclosing instance of type Demo is accessible. Must qualify the allocation with an enclosing instance of type Demo (e.g. x.new A() where x is an instance of Demo).
    hiberbnate 缓存策略概述
    一分钟看你缺乏哪种维生素
    zrrx笔试题(一)——文件复制&日期天数差
  • 原文地址:https://www.cnblogs.com/Xunqf/p/4238924.html
Copyright © 2011-2022 走看看