我试图调整UINavigationBar的高度以使其更小但我的视图显示导航栏曾经是黑色视图。我尝试改变我的视图框架以覆盖这个黑色区域,但它似乎没有起作用。
代码:
- (IBAction)reduceNavigationBarHeight:(id)sender {
CGRect frameToChange = self.navigationController.navigationBar.frame;
frameToChange.size.height -= 5;
self.navigationController.navigationBar.frame = frameToChange;
CGRect viewFrame = self.view.frame;
viewFrame.origin.y -= 5;
viewFrame.size.height += 5;
self.view.frame = viewFrame;
}
答案 0 :(得分:0)
我认为它是状态栏,你可以隐藏
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)])
{
// iOS 7
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
} else
{
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
答案 1 :(得分:0)
请尝试以下代码
-(void)viewDidLayoutSubviews
{
CGRect frameToChange = self.navigationController.navigationBar.frame;
frameToChange.size.height -= 5;
self.navigationController.navigationBar.frame = frameToChange;
}
或
如果您正在使用Autolayout -
CGRect frameToChange = self.navigationController.navigationBar.frame;
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:navigationBar attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1 constant:frameToChange.size.height - 5.0]];