iPhone 应用程序更改 willChangeStatusBarFrame 上的视图并暂停

发布于 2024-10-02 07:55:25 字数 451 浏览 4 评论 0原文

在我的应用程序中,我有一个 UINavigationController 和一个以编程方式创建的 UINavigationBar。 UINavigationBar 在视图中具有自定义定位,但每当调用 will/didChangeStatusBarFrame 时(当您启用通话中状态栏时),或者应用程序暂停和恢复时,navBar 都会自动移回屏幕顶部。

我可以通过将导航栏保持在底部来稍微覆盖此行为,但现在它创建了第二个导航栏,并将其移动到顶部。

为什么会发生这种情况,我该如何防止这种情况发生?这是 iOS 4 的一个新问题 - 该应用程序在 2.x 和 3.x 中都运行良好。

另外,在开始讨论人机界面指南之前,请注意,我知道 Apple 不希望 UINavigationBars 位于底部。然而,这是一个自定义应用程序,将由我和我一个人使用,我要求该栏位于底部。此外,这个问题让我抓狂,无论我的导航栏位于何处,我都想知道答案......

In my application, I have a UINavigationController with a UINavigationBar that I created programmatically. The UINavigationBar has custom positioning within the view, but whenever will/didChangeStatusBarFrame is called (when you enable the in-call status bar), or the app suspends and resumes, the navBar automagically moves back to the top of the screen.

I was able to override this behavior somewhat by keeping my navBar in place at the bottom, but now it creates a SECOND navBar which it moves to the top.

Why is this happening, and how do I prevent it from happening? This is a new issue with iOS 4 - the app ran fine in both 2.x and 3.x.

Also, before a discussion about Human Interface Guidelines is started, please note that I'm aware Apple doesn't want UINavigationBars at the bottom. However, this is a custom app that will be used by me and me alone, and I require that the bar be at the bottom. Additionally, this issue is driving me nuts and I want to know the answer no matter where my navBar lies...

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

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

发布评论

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

评论(1

Oo萌小芽oO 2024-10-09 07:55:25

哎呀,这有点像黑客,但它确实有效。
要在显示通话状态时将导航栏保持在底部:

- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame {
    [navigationController setNavigationBarHidden:YES];
}

- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame {
    [navigationController setNavigationBarHidden:NO];
    CGSize s2 = navBar.bounds.size;
    [navBar setFrame:CGRectMake(0, [navigationController.view bounds].size.height-s2.height, s2.width, s2.height)];

}

并且由于使用此应用程序进行多任务处理不仅是不必要的,而且也是不需要的,因此我通过将以下内容添加到 plist 来禁用它:

Application does not run in background

这仍然没有真正回答我的问题关于为什么导航栏跳到顶部,这是一个黑客修复,但它现在必须工作。

Whelp, this is a bit of a hack, but it works.
To keep the navBar at the bottom when the in-call status is displayed:

- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame {
    [navigationController setNavigationBarHidden:YES];
}

- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame {
    [navigationController setNavigationBarHidden:NO];
    CGSize s2 = navBar.bounds.size;
    [navBar setFrame:CGRectMake(0, [navigationController.view bounds].size.height-s2.height, s2.width, s2.height)];

}

And since multitasking with this app is not only unnecessary but also unwanted, I disabled it by adding the following to the plist:

Application does not run in background

This still doesn't really answer my question about why the navBar was jumping to the top, and it's a hackish fix, but it will have to work for now.

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