gpt4 book ai didi

ios - 自定义 UINavigationBar 高度 : how do I adjust the content views?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:23:30 29 4
gpt4 key购买 nike

我的应用程序有一个 59(虚拟)像素高的自定义导航栏,而不是标准 Apple UINavigationController UINavigationBar 的 44 像素。我在应用程序启动期间通过以下调用将样式应用于栏:

UIImage *navBarImage = [UIImage imageNamed:@"navigation-bar.png"];
[[UINavigationBar appearance] setBackgroundImage:navBarImage
forBarMetrics:UIBarMetricsDefault];

这导致的问题是,它基本上是在标准导航栏的原点处拍打在屏幕顶部的图像。底层导航栏不知道它的大小已经改变。这使得内容 View (推送到导航堆栈的 View )显示在自定义栏下方 15 像素处。

我找不到改变 UINavigationController's navigation view 的大小和位置的方法.

考虑这种定制的最优雅的方式是什么?以下(不优雅)有效,但因为操作是在 View 渲染后应用的,所以位置的变化和大小的调整对用户来说非常明显,看起来很业余:

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

CGRect frame = self.view.frame;
self.view.frame = CGRectMake(frame.origin.x, frame.origin.y + 15, frame.size.width, frame.size.height - 15);
}

所有推送到导航堆栈的 Controller 都在实现上述方法的 UIViewController 的子类中。

非常感谢!

最佳答案

我知道这已经过时了,但由于您从未得到答案,我想我可能会发布我是如何解决这个问题的。

我发布了一个类似的问题,但除了你的问题之外还有另一个问题。我被指向了a question on how to set the height of a UINavigationBar ,而最佳答案对我来说非常有效。用户建议创建自定义 UINavigationBar 类别并覆盖 -sizeThatFits 方法。它解决了您的应用无法识别 UINavigationBar 增加的高度的问题,以及 UINavigationBar 中的 View 在默认 44px 底线以下无法点击的其他问题。

关于ios - 自定义 UINavigationBar 高度 : how do I adjust the content views?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12541512/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com