UINavigationController属性 & 导航栏透明度影响下边子视图的原点位置
2015-12-01 19:25
483 查看
//UINavigationController
导航视图控制器, 是用来管理视图控制器的控制器
#warning 注意:
每个导航视图控制器, 至少有一个视图控制器
RootViewController *root = [[RootViewController
alloc]init];
UINavigationController *firstNevigation = [[UINavigationController
alloc]initWithRootViewController:root];
//通常导航视图控制器的通用设置,
在创建导航视图控制器时设置
//iOS中状态栏高度20px,
导航栏高度44px(竖屏), 32px(横屏).
//iOS7.0之前导航栏默认是不透明的, ios7.0之后默认是透明的
#warning 注意:
如果导航条透明状态, 那么原点在屏幕的左上角.如果导航条不透明,
那么原点在屏幕左上角下面64px的位置.
//透明度translucent是导航栏的属性,
不是导航视图控制器的属性
//控制导航条透明
属性: translucent
// firstNevigation.navigationBar.translucent = NO;
//设置导航栏的背景颜色
属性:barTintColor
// firstNevigation.navigationBar.barTintColor = [UIColor cyanColor];
//设置导航栏的样式
属性:barStyle (只有黑白两种样式,
默认是白色)
firstNevigation.navigationBar.barStyle =
UIBarStyleDefault;
//设置导航条的背景图片
[firstNevigation.navigationBar
setBackgroundImage:[UIImage
imageNamed:@"NavBar_64"]
forBarMetrics:UIBarMetricsDefault];
//将导航视图控制器设置成window的根视图控制器
//UINavigationController
继承自 UIViewController
//屏幕上方多了一个导航栏,
导航条尺寸固定
self.window.rootViewController = firstNevigation;
RootViewController.m:
//设置当前页导航栏中的标题
// self.navigationItem.title = @"首页";
//该控制器视图的导航栏的显示内容
居中显示 并且进入下一页后, back变为"首页"
self.title =
@"首页";
//设置当前导航栏中自定义标题视图
属性:titleView
// UISegmentedControl *titleSegmented = [[UISegmentedControl alloc]initWithItems:@[@"消息", @"电话"]];
//
// titleSegmented.frame = CGRectMake(0, 0, self.view.frame.size.width, 30);
//
// //添加导航栏的显示内容
默认居中显示 x ,y不起作用
// self.navigationItem.titleView = titleSegmented;
//在当前页的导航栏上添加左面按钮
UIBarButtonItem *firstBarButton = [[UIBarButtonItem
alloc]initWithImage:[UIImage
imageNamed:@"Navigation-Btn-History-Highlighted@2x"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(collectionAction)];
UIBarButtonItem *secondBarButton = [[UIBarButtonItem
alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self
action:@selector(cameraPhoto)];
//添加自定义视图到导航栏按钮
UIButton *button = [UIButton
buttonWithType:UIButtonTypeCustom];
button.frame =
CGRectMake(0,
0, 30,
20);
[button setTitle:@"GD"
forState:UIControlStateNormal];
[button addTarget:self
action:@selector(gdAction:)
forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor
blackColor];
UIBarButtonItem *threeButtonItem = [[UIBarButtonItem
alloc]initWithCustomView:button];
// self.navigationItem.leftBarButtonItem = firstBarButton;
//设置导航栏一组按钮
self.navigationItem.leftBarButtonItems =
@[threeButtonItem, firstBarButton, secondBarButton];
[firstBarButton
release];
[secondBarButton
release];
//如果系统提供的barButtonItem大小,
样式,
位置不能满足要求时, 那么使用自定义的视图,
通过UIBarButtonItem的initWithCustomerView:
来添加自己想要的视图
//设置导航条上图片的渲染颜色 (一般导航栏中的按钮图片都是镂空的,
镂空图片变为red)
// self.navigationController.navigationBar.tintColor = [UIColor redColor];
self.navigationController.navigationBar.translucent = YES;
导航控制器的导航栏的透明度为YES时, 即透明, 受导航控制器控制的视图的(0, 0)即为其子视图的原点位置, 即子视图的最高显示高度(self.view.frame.size.height)为总视图的高度(self.view.frame.size,height)
self.navigationController.navigationBar.translucent = NO;
反之, 透明度为NO时, 即不透明, 导航控制器控制的视图的(0,64)即为其子视图的原点位置, 即子视图的最高显示高度为: (self.view.frame.size.height - 64)
)
64px = 20px (状态栏高度) + 44px(导航栏高度) //导航栏横屏的高度为32px
导航视图控制器, 是用来管理视图控制器的控制器
#warning 注意:
每个导航视图控制器, 至少有一个视图控制器
RootViewController *root = [[RootViewController
alloc]init];
UINavigationController *firstNevigation = [[UINavigationController
alloc]initWithRootViewController:root];
//通常导航视图控制器的通用设置,
在创建导航视图控制器时设置
//iOS中状态栏高度20px,
导航栏高度44px(竖屏), 32px(横屏).
//iOS7.0之前导航栏默认是不透明的, ios7.0之后默认是透明的
#warning 注意:
如果导航条透明状态, 那么原点在屏幕的左上角.如果导航条不透明,
那么原点在屏幕左上角下面64px的位置.
//透明度translucent是导航栏的属性,
不是导航视图控制器的属性
//控制导航条透明
属性: translucent
// firstNevigation.navigationBar.translucent = NO;
//设置导航栏的背景颜色
属性:barTintColor
// firstNevigation.navigationBar.barTintColor = [UIColor cyanColor];
//设置导航栏的样式
属性:barStyle (只有黑白两种样式,
默认是白色)
firstNevigation.navigationBar.barStyle =
UIBarStyleDefault;
//设置导航条的背景图片
[firstNevigation.navigationBar
setBackgroundImage:[UIImage
imageNamed:@"NavBar_64"]
forBarMetrics:UIBarMetricsDefault];
//将导航视图控制器设置成window的根视图控制器
//UINavigationController
继承自 UIViewController
//屏幕上方多了一个导航栏,
导航条尺寸固定
self.window.rootViewController = firstNevigation;
RootViewController.m:
//设置当前页导航栏中的标题
// self.navigationItem.title = @"首页";
//该控制器视图的导航栏的显示内容
居中显示 并且进入下一页后, back变为"首页"
self.title =
@"首页";
//设置当前导航栏中自定义标题视图
属性:titleView
// UISegmentedControl *titleSegmented = [[UISegmentedControl alloc]initWithItems:@[@"消息", @"电话"]];
//
// titleSegmented.frame = CGRectMake(0, 0, self.view.frame.size.width, 30);
//
// //添加导航栏的显示内容
默认居中显示 x ,y不起作用
// self.navigationItem.titleView = titleSegmented;
//在当前页的导航栏上添加左面按钮
UIBarButtonItem *firstBarButton = [[UIBarButtonItem
alloc]initWithImage:[UIImage
imageNamed:@"Navigation-Btn-History-Highlighted@2x"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(collectionAction)];
UIBarButtonItem *secondBarButton = [[UIBarButtonItem
alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self
action:@selector(cameraPhoto)];
//添加自定义视图到导航栏按钮
UIButton *button = [UIButton
buttonWithType:UIButtonTypeCustom];
button.frame =
CGRectMake(0,
0, 30,
20);
[button setTitle:@"GD"
forState:UIControlStateNormal];
[button addTarget:self
action:@selector(gdAction:)
forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor
blackColor];
UIBarButtonItem *threeButtonItem = [[UIBarButtonItem
alloc]initWithCustomView:button];
// self.navigationItem.leftBarButtonItem = firstBarButton;
//设置导航栏一组按钮
self.navigationItem.leftBarButtonItems =
@[threeButtonItem, firstBarButton, secondBarButton];
[firstBarButton
release];
[secondBarButton
release];
//如果系统提供的barButtonItem大小,
样式,
位置不能满足要求时, 那么使用自定义的视图,
通过UIBarButtonItem的initWithCustomerView:
来添加自己想要的视图
//设置导航条上图片的渲染颜色 (一般导航栏中的按钮图片都是镂空的,
镂空图片变为red)
// self.navigationController.navigationBar.tintColor = [UIColor redColor];
self.navigationController.navigationBar.translucent = YES;
导航控制器的导航栏的透明度为YES时, 即透明, 受导航控制器控制的视图的(0, 0)即为其子视图的原点位置, 即子视图的最高显示高度(self.view.frame.size.height)为总视图的高度(self.view.frame.size,height)
self.navigationController.navigationBar.translucent = NO;
反之, 透明度为NO时, 即不透明, 导航控制器控制的视图的(0,64)即为其子视图的原点位置, 即子视图的最高显示高度为: (self.view.frame.size.height - 64)
)
64px = 20px (状态栏高度) + 44px(导航栏高度) //导航栏横屏的高度为32px
相关文章推荐
- ios UINavigationController
- String和StringBuilder、StringBuffer的区别?
- 利用协议代理实现导航控制器UINavigationController视图之间的正向传值和反向传值
- 重写系统中的UINavigationController 返回按钮的事件
- .htaccess 中 %{REQUEST_FILENAME} 及其参数的意思
- networkRequest
- QNetworkRequest 请求类
- VC皮肤库之duilib
- directUI
- UESTC 1222 Sudoku
- \backend\models\core\Request
- MediaCodec 编码H264 编码一帧后dequeueOutputBuffer为-1的问题
- 1041. Be Unique (20)
- 理解百度云推送的几个概念
- does not contain bitcode. You must rebuild it with
- Android中的Looper,Handler,Message和MessageQueue
- form builder视图窗口下找不到堆叠视图项
- poj--1904--King's Quest(scc建图)
- poj--1904--King's Quest(scc建图)
- 设置输入框随字数自动伸缩