当我用 UIView 覆盖所有屏幕时,如何用 UIView 覆盖 UIStatusBar? (iPhone)

发布于 2024-08-17 18:36:24 字数 52 浏览 3 评论 0原文

当我用 UIView 覆盖所有屏幕时,如何用 UIView 覆盖 UIStatusBar?

How to cover also the UIStatusBar with UIView when i cover all the screen with the UIView?

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

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

发布评论

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

评论(4

暮凉 2024-08-24 18:36:24

我也纠结了好久要怎么做!终于弄清楚了:)关键是将新窗口的 windowLevel 设置为非常高,以便它位于所有其他窗口/视图/状态栏等之上:

UIWindow *keyWin = [UIApplication sharedApplication].keyWindow;
UIWindow *hudWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0.0f, 0.0f, keyWin.frame.size.width, keyWin.frame.size.height)];
hudWindow.backgroundColor = [UIColor blackColor];
hudWindow.alpha = 0.60;
[hudWindow setWindowLevel:10000.0f];
[hudWindow setHidden:NO];

享受吧!

I was battling how to do this for a long time too! Finally figured it out :) The key is to set the windowLevel of your new window to really high so it lives on top of all the other windows/views/statusbar etc:

UIWindow *keyWin = [UIApplication sharedApplication].keyWindow;
UIWindow *hudWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0.0f, 0.0f, keyWin.frame.size.width, keyWin.frame.size.height)];
hudWindow.backgroundColor = [UIColor blackColor];
hudWindow.alpha = 0.60;
[hudWindow setWindowLevel:10000.0f];
[hudWindow setHidden:NO];

Enjoy!

孤独难免 2024-08-24 18:36:24

您能做的最好的事情就是使用以下命令隐藏状态栏:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]

并在需要时再次显示它。

基本上,您可以随时removeFromSuperview 删除视图。

The best thing you can do is hide the status bar with:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]

and show it again when you need it.

You can basically removeFromSuperview any time you want to remove the view.

怪我太投入 2024-08-24 18:36:24

如果您尝试创建类似 UIAlertView 的效果,我认为您无法做到这一点。您可以通过 http://bugreporter.apple.com 向 Apple 提交功能增强请求。

If you're trying to create a UIAlertView-like effect, I don't think you can do this. You might file a feature enhancement request with Apple at http://bugreporter.apple.com.

讽刺将军 2024-08-24 18:36:24

很好,但我做了这两个改变。将 1.0 添加到 UIWindowLevel 仍然会隐藏状态栏,我不知道为什么。

self.windowLevel = UIWindowLevelStatusBar+2.0f;

self.userInteractionEnabled = NO;

将 Statusbar userInteractionEnabled 属性设置为 NO 将确保当有人点击此状态栏时,您的滚动视图将滚动到顶部。

Nice, but I made these two changes. Adding 1.0 to UIWindowLevel still hides the status bar, and I have no idea why.

self.windowLevel = UIWindowLevelStatusBar+2.0f;

self.userInteractionEnabled = NO;

Setting the Statusbar userInteractionEnabled property to NO will ensure that your scroll views will scroll to top when someone taps on this statusbar.

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