改UINavigationBar的高度

改UINavigationBar的高度

本文介绍了如何更改UINavigationBar的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题使我瘫痪了一天多.我需要修改UINavigationBar的高度.

This issue has crippled me for over a day. I need to modify the UINavigationBar's height.

像这样在AppDelegate中创建UINavigationController.

The UINavigationController is created in the AppDelegate like so.

self.navigationController = [[UINavigationController alloc] initWithRootViewController:mainController];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];

如果我将[self.navigationController.navigationBar setFrame:newFrame]添加到 viewDidAppear (如以下代码),导航栏的高度更改并保持不变.

The height of the navbar WILL change and stick if I add [self.navigationController.navigationBar setFrame:newFrame] to viewDidAppear like the code below.

- (void)viewWilAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    CGRect newFrame = CGRectMake(0, 0, 320, 100);
    [self.navigationController.navigationBar setFrame:newFrame]
}

但是,如果我这样做,您实际上可以在视图加载的瞬间看到帧从原始的44px跳到100px的高度,这很烦人.

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.

我尝试在启动UINavigationController之后将[navBar setFrame:]添加到rootViewController的 viewDidload viewWillAppear 以及AppDelegate中.这些都不起作用.

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.

请注意,我已经使用下面的代码重写了UINavigationBar类别中的drawRect:(CGRect)rect方法,以使背景颜色变为纯黑色,但我认为这与问题无关.

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.

[[UIColor blackColor] set];
CGContextFillRect(UIGraphicsGetCurrentContext(), rect);

有人知道最好的方法吗?

Does anyone know the best way to do this?

推荐答案

"如果需要提供更多控件集,或者不需要启用导航功能,请使用工具栏代替导航栏."-从 iOS人机界面准则.

"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.

这篇关于如何更改UINavigationBar的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:22