UINavigationBar 总结
一、某个 ViewController 出现隐藏 NavigationBar
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:NO]; } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; [self.navigationController setNavigationBarHidden:NO animated:NO]; }
二、调整 NavigationBar 高度
1、介绍
1) 默认是 44 个像素点。
2、使用
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title = @"AAAAA"; UIBarButtonItem* leftBarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Action_Moments.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(onclickBackBarButton)]; self.navigationItem.leftBarButtonItem = leftBarButton; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; CGRect rect = self.navigationController.navigationBar.frame; rect.size.height = 100.0f; self.navigationController.navigationBar.frame = rect; [self.navigationController.navigationBar setTitleVerticalPositionAdjustment:-40.0f forBarMetrics:UIBarMetricsDefault]; // [self.navigationItem.backBarButtonItem setBackgroundVerticalPositionAdjustment:-40.0f forBarMetrics:UIBarMetricsDefault]; // 对系统自带的 backBarButton 不起作用 [self.navigationItem.leftBarButtonItem setBackgroundVerticalPositionAdjustment:-40.0f forBarMetrics:UIBarMetricsDefault]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; CGRect rect = self.navigationController.navigationBar.frame; rect.size.height = 44.0f; self.navigationController.navigationBar.frame = rect; }
注意:
1) 如果使用系统默认的 backBarButton 是不能调整高度的。
2) 只有自定的 barButtonItem,而且使用以下初始化,才可以调整其高度。
- (id)initWithImage:(UIImage *)image style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action
posted on 2014-03-30 21:36 EileenLeung 阅读(1091) 评论(0) 编辑 收藏 举报