This issue has crippled me for over a day. I need to modify the UINavigationBar's height.
这个问题已经使我瘫痪了一天多。我需要修改UINavigationBar的高度。
The UINavigationController is created in the AppDelegate like so.
UINavigationController在AppDelegate中创建,就像这样。
self.navigationController = [[UINavigationController alloc] initWithRootViewController:mainController];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
The height of the navbar WILL change and stick if I add [self.navigationController.navigationBar setFrame:newFrame] to viewDidAppear like the code below.
如果我将[self.navigationController.navigationBar setFrame:newFrame]添加到viewDidAppear,导航栏的高度将会改变并粘住,如下面的代码所示。
- (void)viewWilAppear:(BOOL)animated
{
[super viewWillAppear:animated];
CGRect newFrame = CGRectMake(0, 0, 320, 100);
[self.navigationController.navigationBar setFrame:newFrame]
}
HOWEVER, if I do it this way, you can actually see the frame snapping from the original 44px to a 100px height in the split second that the view loads, which is very annoying.
但是,如果我这样做,你实际上可以看到框架从原始的44px捕捉到视图加载的瞬间的100px高度,这非常令人讨厌。
I've tried adding the [navBar setFrame:] to viewDidload, viewWillAppear of the rootViewController and also the AppDelegate just after I initiate the UINavigationController. None of these work.
我尝试在启动UINavigationController之后将[navBar setFrame:]添加到rootViewController的viewDidload,viewWillAppear以及AppDelegate。这些都不起作用。
Just so you know, I've overridden the drawRect:(CGRect)rect method in a UINavigationBar category to make the background color solid black using the code below but I don't think that has something to do with the problem.
您知道,我已经覆盖了UINavigationBar类别中的drawRect:(CGRect)rect方法,使用下面的代码使背景颜色变为黑色,但我不认为这与问题有关。
[[UIColor blackColor] set];
CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
Does anyone know the best way to do this?
有谁知道这样做的最佳方法?
1 个解决方案
#1
1
"Use a toolbar instead of a navigation bar if you need to offer a larger set of controls, or you do not need to enable navigation." - From the iOS Human Interface Guidelines under Navigation Bar / Guidelines.
“如果您需要提供更多控件,或者您不需要启用导航,请使用工具栏而不是导航栏。” - 来自导航栏/指南下的iOS人机界面指南。
#1
1
"Use a toolbar instead of a navigation bar if you need to offer a larger set of controls, or you do not need to enable navigation." - From the iOS Human Interface Guidelines under Navigation Bar / Guidelines.
“如果您需要提供更多控件,或者您不需要启用导航,请使用工具栏而不是导航栏。” - 来自导航栏/指南下的iOS人机界面指南。