zoukankan      html  css  js  c++  java
  • UINavigationController 、UINavigationBar 、UINavigationItem 超清晰直观详解(扩展)

    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(即启动画面)的时候才能隐藏状态栏。如果想要在启动画面开始即隐藏状态栏,则要修改app的info.plist文件,新增UIStatusBarHidden键(Status bar is initially hidden),其值是YES。

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

    导航条Navigation Bar

    [self.navigationController setNavigationBarHidden:YES];

     

    选项卡TabBar

    方法一:

    [self.tabBarController.tabBar setHidden:YES];

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

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

    复制代码
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
    {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    // Custom initialization.
    self.hidesBottomBarWhenPushed = YES;
    }
    return self;
    }
    复制代码

    方法三:

    复制代码
    - (void)makeTabBarHidden:(BOOL)hide
    {
    if ( [self.tabBarController.view.subviews count] < 2 )
    {
    return;
    }
    UIView *contentView;

    if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
    {
    contentView = [self.tabBarController.view.subviews objectAtIndex:1];
    }
    else
    {
    contentView = [self.tabBarController.view.subviews objectAtIndex:0];
    }
    // [UIView beginAnimations:@"TabbarHide" context:nil];
    if ( hide )
    {
    contentView.frame = self.tabBarController.view.bounds;
    }
    else
    {
    contentView.frame = CGRectMake(self.tabBarController.view.bounds.origin.x,
    self.tabBarController.view.bounds.origin.y,
    self.tabBarController.view.bounds.size.width,
    self.tabBarController.view.bounds.size.height - self.tabBarController.tabBar.frame.size.height);
    }

    self.tabBarController.tabBar.hidden = hide;
    // [UIView commitAnimations];
    }
    复制代码

    时机

    复制代码
    - (void)viewWillAppear:(BOOL)animated 
    {
    [self setFullScreen:YES];
    }
    - (void)viewWillDisappear:(BOOL)animated
    {
    [self setFullScreen:NO];
    }
    - (void)setFullScreen:(BOOL)fullScreen
    {
    // 状态条
    [UIApplication sharedApplication].statusBarHidden = fullScreen;
    // 导航条
    [self.navigationController setNavigationBarHidden:fullScreen];
    // tabBar的隐藏通过在初始化方法中设置hidesBottomBarWhenPushed属性来实现
    }

    参考:http://www.cnblogs.com/pengyingh/articles/2381725.html

    设置UINavigationBar的透明度

    方法1:

    self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

    方法2:

    [self.navigationController.navigationBar setAlpha:0.5];不过看到的是window的背景

    NavigationBar在64位ios中的特性

    //navigationBar的背景色设置为黄色   iphone5s 64位操作系统,使用下面的方法,将导致navigationBar的大小扩大一倍,self.view的位置整体下移一个navigationbar的距离

        //[self.navigationController.navigationBar setBackgroundImage:[ImageUtilities createImageWithColor:[ColorUtils colorWithHexString:orange_color]] forBarMetrics:UIBarMetricsDefault];

    viewDidLoad和viewWillAppear的区别

    NavigationController 在从BController  pop回AController时,如果 AController的View还在,程序是不会再执行AController的viewDidLoad方法的。但程序回执行AController的viewAppear方法,这就是为什么NavigationBar的很多定制化属性,要写在viewWillAppear中。而不是viewDidLoad中。

     
  • 相关阅读:
    Hello iOS
    钝化程序、逻辑冻结、冻结程序的延续、瞬间转移
    对字符串操作的各种笔试题
    .NET各大平台数据列表控件绑定原理及比较(WebForm、Winform、WPF)
    多线程计算----pthread
    Xcode的Hello World(简单易懂)
    two sets of Qt binaries into the same process的解决办法
    微软新一代输入法框架 TSF
    Starting the application on Mac does not work(拷贝platforms到不同的位置,才能解决问题),还可设置DYLD_PRINT_LIBRARIES=1 观察动态库
    dddd
  • 原文地址:https://www.cnblogs.com/ygm900/p/3664380.html
Copyright © 2011-2022 走看看