创建半透明覆盖层来模仿 UIAlertView 或 UIActionSheet?
在我当前正在开发的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有这样做,但是如果您想在状态栏上覆盖任何内容,我想说您必须创建一个
UIWindow
实例并设置其windowLevel
到UIWindowLevelStatusBar
。或者在视图层次结构中找到状态栏窗口并向其添加半不透明的子视图。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 itswindowLevel
toUIWindowLevelStatusBar
. Or find the status bar window in the view hierarchy and add a semi-opaque subview to it.