创建半透明覆盖层来模仿 UIAlertView 或 UIActionSheet?

发布于 2024-08-25 01:37:50 字数 394 浏览 8 评论 0原文

在我当前正在开发的 iPhone 应用程序中,我呈现了几个模仿 UIAlertView 和 UIActionSheet 行为的“警报”视图。这些视图需要 UIAlertView 或 UIActionSheet 中不可用的非标准元素。我没有尝试子类化其中任何一个,而是创建了自己的类,以便可以轻松地自定义警报的外观和感觉。

我遇到的一个问题是,当呈现警报视图时,我无法使 iPhone 屏幕褪色。当以与 UIAlertView 和 UIActionSheet 相同的方式呈现自定义视图时,我想淡出整个屏幕(包括状态栏)。我试图通过在整个屏幕上覆盖半透明视图来实现此目的,但无论我是否将视图添加为 keyWindow 的子视图或最上面的视图,状态栏都不会被遮挡。

有人对如何实现这一目标有任何建议吗?这看起来应该很简单,所以我可能忽略了一些东西。

In the iPhone app that I am currently developing, I present several "alert" views that mimic the behaviour of UIAlertView and UIActionSheet. These views require non-standard elements that are not available in UIAlertView or UIActionSheet. Rather than attempt to subclass either, I have created my own classes so that I can easily customize the look and feel of the alerts.

The one problem I am having with this is that I am having trouble fading the iPhone screen when the alert views are presented. I would like to fade out the whole screen (including the status bar) when presenting my custom views in the same way that UIAlertView and UIActionSheet do. I am trying to accomplish this by overlaying a semi-transparent view over the whole screen, but regardless of whether I add the view as a subview of the keyWindow or the topmost view, the status bar never gets shaded.

Does anyone have any suggestions on how to accomplish this? This seems like something that should be simple to do, so I'm probably overlooking something.

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

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

发布评论

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

评论(1

三生路 2024-09-01 01:37:50

我还没有这样做,但是如果您想在状态栏上覆盖任何内容,我想说您必须创建一个 UIWindow 实例并设置其 windowLevelUIWindowLevelStatusBar。或者在视图层次结构中找到状态栏窗口并向其添加半不透明的子视图。

I haven't done this, but if you want to overlay anything over the status bar, I'd say you'll have to create a UIWindow instance and set its windowLevel to UIWindowLevelStatusBar. Or find the status bar window in the view hierarchy and add a semi-opaque subview to it.

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