iOS获取当前页面导航栏标签栏高度

// 状态栏(statusbar)    手机最上面的一条高20的部分
CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];  
NSLog(@"status width - %f", rectStatus.size.width); // 宽度  320
NSLog(@"status height - %f", rectStatus.size.height);   // 高度  20

  

// 导航栏(navigationbar)  20-64之间部分
CGRect rectNav = self.navigationController.navigationBar.frame;  
NSLog(@"nav width - %f", rectNav.size.width); // 宽度  320
NSLog(@"nav height - %f", rectNav.size.height);   // 高度  44

//标签栏tabBar
CGRect rectTabBar = self.navigationController.tabBarController.tabBar.frame;

应用场景1:
1.我的界面在标签栏上面加一个frame不变的退出按钮
CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
CGRect rectNav = self.navigationController.navigationBar.frame;
UIView * EXITView = [[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-flexibleHeight(44)-rectTabBar.size.height, SCREEN_WIDTH, flexibleHeight(44))];
EXITView.backgroundColor = [UIColor redColor];
UIButton * exitBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, EXITView.frame.size.height)];
exitBtn.backgroundColor = [UIColor clearColor];
[exitBtn setTitle:@"安全退出" forState:UIControlStateNormal];
[exitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
exitBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
[exitBtn addTarget:self action:@selector(exitOnclick) forControlEvents:UIControlEventTouchDown];
[EXITView addSubview:exitBtn];
[self.view addSubview:EXITView];

应用场景2:
给某个界面加一个banner
CGRect rectNav = self.navigationController.navigationBar.frame;

    _bannerImgView = [[UIImageView alloc]initWithFrame:CGRectMake(flexibleWidth(0), rectNav.size.height+flexibleHeight(19), SCREEN_WIDTH, flexibleHeight(133))];
    [_bannerImgView setImage:[UIImage imageNamed:@"dahui_banner"]];
    _bannerImgView.backgroundColor = [UIColor blackColor];

你可能感兴趣的:(iOS获取当前页面导航栏标签栏高度)