UINavigationController属性 & 导航栏透明度影响下边子视图的原点位置




 //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大小, 样式, 位置不能满足要求时, 那么使用自定义的视图, 通过UIBarButtonIteminitWithCustomerView: 来添加自己想要的视图

    

    

    

    //设置导航条上图片的渲染颜色 (一般导航栏中的按钮图片都是镂空的, 镂空图片变为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






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值