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。
同理:对于状态栏的颜色改变,也要分别从两处着手,代码[[UIApplicationsharedApplication] setStatusBarStyle: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属性来实现
}
设置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中。
UINavigationController 、UINavigationBar 、UINavigationItem 超清晰直观详解(扩展)的更多相关文章
- UINavigationController 、UINavigationBar 、UINavigationItem 超清晰直观详解
UINavigationController 部分 1. UINavigationController 是一个容器类.里面盛放的是UIViewController. 容器的意思是,如果你不放入UIVi ...
- Android项目刮刮奖详解扩展篇——开源刮刮奖View的制作
Android项目刮刮奖详解(四) 前言 我们已经成功实现了刮刮奖的功能了,本期是扩展篇,我们把这个View直接定义成开源控件,发布到JitPack上,以后有需要也可以直接使用,关于自定义控件的知识, ...
- PHP超全局变量$_ENV详解,及$_ENV为空的可能原因
PHP中的$_ENV存储了一些系统的环境变量,因为牵扯到实际的操作系统,所以不可能给出$_ENV的完整列表. $_ENV为空的可能原因: 你的php.ini的variables_order值为&qu ...
- 详解扩展欧几里得算法(扩展GCD)
浅谈扩展欧几里得(扩展GCD)算法 本篇随笔讲解信息学奥林匹克竞赛中数论部分的扩展欧几里得算法.为了更好的阅读本篇随笔,读者最好拥有不低于初中二年级(这是经过慎重考虑所评定的等级)的数学素养.并且已经 ...
- IP2——IP地址和子网划分学习笔记之《子网掩码详解》
2018-05-04 16:21:21 在学习掌握了前面的<进制计数><IP地址详解>这两部分知识后,要学习子网划分,首先就要必须知道子网掩码,只有掌握了子网掩码这部分内容 ...
- IP地址和子网划分学习笔记之《IP地址详解》
2018-05-03 18:47:37 在学习IP地址和子网划分前,必须对进制计数有一定了解,尤其是二进制和十进制之间的相互转换,对于我们掌握IP地址和子网的划分非常有帮助,可参看如下目录详文. ...
- Linux 正则表达式详解
正则表达式(REGULAR):为处理大量的字符串而定义的一套规则和方法,为了处理大量字符串而生 常见命令参数 基础正则表达式 . :有且只有任意一个字符(包括空格) * :重复前面任意0或者多个字符 ...
- UI第六节——UINavigationController 详解
1. UINavigationController 是一个容器类.里面盛放的是UIViewController. 容器的意思是,如果你不放入UIViewController,里面就是空的,什么也没有. ...
- iOS开发——控制器OC篇&UINavigationController&UITabBarController详解
UINavigationController&UITabBarController详解 一:UINavigationController 控制器的属性: UINavigationControl ...
随机推荐
- findHomography和perspectiveTransform
opencv中的两个函数,之前一直不明白这俩函数到底是要干嘛的. 得到两帧图像中的特征点后,就可以用findHomography得到单应性矩阵. 得到单应性矩阵后,可以 (1)根据相应的计算方法,由前 ...
- VC++一些开发心得与调试技巧
1.如何在Release状态下进行调试 Project->Setting=>ProjectSetting对话框,选择Release状态.C/C++标签中的Category选Gen ...
- Sqlserver中PIVOT行转列透视操作
创建表: IF OBJECT_ID('T040_PRODUCT_SALES') IS NOT NULL DROP TABLE T040_PRODUCT_SALES create table T040_ ...
- php生成随机数
生成1-10之间的随机数,不重复. 方法一:用shuffle函数. <?php $arr=range(1,10); shuffle($arr); foreach($arr as $values) ...
- IntelliJ IDEA :Error:(1, 1) java: 非法字符: '\ufeff'
将file encodings由utf-8改成utf-16,再将utf-16改成utf-8就好了
- RocketMQ 部署
1. 下载 下载RocketMQwget https://github.com/alibaba/RocketMQ/releases/download/v3.2.6/alibaba-rocketmq-3 ...
- 【LOJ】#6433. 「PKUSC2018」最大前缀和
题解 神仙的状压啊QAQ 设一个\(f[S]\)表示数字的集合为\(S\)时\(sum[S]\)为前缀最大值的方案数 \(g[S]\)表示数字集合为\(S\)时所有前缀和都小于等于0的方案数 答案就是 ...
- has the wrong structure
mysql 5.6升级到5.7之后报错 root@localhost:mysql.sock [test]>show variables like '%log%' ; ERROR 1682 (HY ...
- [C编码笔记] 空串与NULL是不一样的
int main() { char *str = NULL; printf("%p \n", str); printf("%p \n", &str); ...
- SpringMVC框架07——服务器端JSR303数据校验
1.数据校验概述 数据校验分为客户端校验和服务器端校验,客户端主要是通过过滤正常用户的误操作,是第一道防线,一般使用JavaScript代码实现.但是只有客户端校验是不够的,攻击者可以绕过客户端验证直 ...