UINavigationController 将视图永久提升 20 点,保留 UINavigatinBar 透明度

发布于 2024-12-18 09:58:58 字数 732 浏览 2 评论 0原文

我的应用程序中有一个 UINavigationController 和一个 UITabBar 。

UINavigationController 有一个半透明的黑色导航栏,如下所示:

在应用程序委托中:

[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent];
    [[UINavigationBar appearance] setAlpha:0.7];

我还隐藏了状态栏,并在 UINavigationBar 的下半部分透明中显示我自己对状态栏的解释,如下所示:

  self.navigationController.view.frame = CGRectMake(0,-22,320,480);

一旦应用程序已加载:UINavigationbar 的下半部分是透明的,我可以在那里显示我自己的状态指示器。

但是,一旦我点击任何 TabBar 选项卡然后返回到原始控制器,就会发生两件事: 由 UINavigationController 管理的视图向下移动,从 UINavigationBar 的下半部分开始。 UINavigationBar 不再透明。 这会使我的 UI 布局中断约 20-22 像素。

如何“说服”我的 UI 记住它的原始布局,而不是在选择不同选项卡时重置为任何它想要的布局?

谢谢。

I have a UINavigationController and a UITabBar within my app.

The UINavigationController has a translucent black navigation bar as follows:

in the app delegate:

[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent];
    [[UINavigationBar appearance] setAlpha:0.7];

I'm also hiding the status bar and displaying my own interpretation of the status bar in the lower, transparent half of the UINavigationBar, like this:

  self.navigationController.view.frame = CGRectMake(0,-22,320,480);

This works once the app has been loaded: the lower half of the UINavigationbar is transparent and I can show my own status indicators there.

However, once I tap on any of the TabBar tabs and then return back to the original controller, 2 things happen:
The view managed by the UINavigationController is shifted down to start at the lower half of the UINavigationBar. The UINavigationBar is no longer transparent.
This breaks the layout of my UI by ~20-22 pixels.

How can I "persuade" my UI to remember it's original layout and not reset to whatever it wants to be when different tabs are selected?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

年少掌心 2024-12-25 09:58:58

我给您的最佳建议是不要自定义构建所有内容,但由于您似乎要完成创建自定义视图的所有工作,所以我会尝试以下操作:

  1. 确保您任何地方都没有代码在您放入新的编辑内容后,它会更改原始视图。在
  2. 没有任何内容的空选项卡之间来回测试,看看原始视图中是否有任何变化。

如果所有其他方法都失败,那么当您调用代码来关闭新选项卡并返回到原始视图时,请重新运行之前用于设置视图的所有代码。如果您将所有用于更改视图的代码放在栏的“构造函数”中,则可以使您自己和系统变得更轻松。

那么您所要做的就是

-(void)ChangeTabs
{
    [UINavigationController dealloc];
    [UINavigationController alloc];
    [UITabView dealloc];
    [UITabView alloc];
}

像这样简单的事情就可以解决您的问题并且仍然高效运行。这取决于你,但我肯定会考虑转向后者,特别是如果你运行多个步骤只是为了正确设置两个栏。

希望这对您有帮助。

My best suggestion to you would be not to custom build everything, but since you seem to be going to all the work of creating a custom view, I would try the following:

  1. Make sure you have no code anywhere that changes the original view after you put the new edits in.
  2. Test going back and forth between empty tabs that have nothing on them and see if anything changes in the original view.

If all else fails, then when you call the code to dismiss the new tabs and return to the original view, re-run all of the previous code you used to set up the view. You can make it easier on yourself and the system if you put all of the code to change the view in the "constructor" of the bars.

Then all you would have to do is

-(void)ChangeTabs
{
    [UINavigationController dealloc];
    [UINavigationController alloc];
    [UITabView dealloc];
    [UITabView alloc];
}

Something simple like this would solve your problem and still run efficiently. It's up to you, but I would definitely consider moving toward the latter, especially if you run multiple steps just to get the two bars set up properly.

Hope this helps you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文