在iOS 8中显示Apple Status Bar上方的UIView [英] Display UIView Above Apple Status Bar in iOS 8

查看:93
本文介绍了在iOS 8中显示Apple Status Bar上方的UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一些关于此问题的帖子,但没有一个问题对我有所帮助。我想在整个屏幕上方显示一个自定义模式,但我想保持Apple状态栏可见。对于模态,我使用一个 UIView 用于调光效果,另一个用于用户将与之交互的实际视图。然后将整个模态作为子视图添加到当前视图并转到前面。本质上,我试图复制UIAlertView的行为,除了自定义视图。以下是我的一些代码:

I know there have been some questions posted about this, but none have helped me with my specific issue. I would like to display a custom modal above the entire screen, but I would like to keep the Apple status bar visible. For the modal, I am using one UIView for the dimming effect and another for the actual view that the user would interact with. The entire modal is then added as a subview to the current view and brought to the front. Essentially, I am trying to replicate the behavior of the UIAlertView, except with a custom view. Here is some of my code:

var modalView:UIView = UIView(frame: self.view.window!.bounds)
modalView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.66)
modalView.addSubview(customView)    

self.view.window!.addSubview(modalView)
modalView.window!.windowLevel = UIWindowLevelStatusBar + 1

self.bringSubviewToFront(modalView)

以上, customView 是用户与之交互的 UIView

Above, customView is the UIView that the user interacts with.

这很好用,但由于某种原因,即使状态栏的样式设置为LightContent,Apple状态栏上的文本也会消失。从代码中可以看出,我没有触摸状态栏。

This works great, but for some reason, the text on the Apple status bar just simply disappears even though the style of the status bar is set to LightContent. As can be seen in the code, I do not touch the status bar.

我试图让状态栏上的文字变暗,就像其余的一样屏幕,我目前卡住了。有没有人对我如何获得理想的行为有任何见解?

I am trying to get the text on the status bar to dim just like the rest of the screen and am currently stuck. Does anyone have any insight on how I can get the desired behavior?

任何帮助都将不胜感激!

Any help would be greatly appreciated!

推荐答案

编辑(2015年11月16日)

我正在从这个主题如下:

这个答案在iOS 8.3+以及可能的iOS 8的早期版本中断了。我不建议任何人使用它,特别是因为它不能保证在未来的iOS版本中工作。

This answer breaks in iOS 8.3+ and possibly previous versions of iOS 8. I DO NOT recommend that anyone uses it, especially since it is not guaranteed to work in future iOS versions.

我的新解决方案使用 UIViewController 的标准 presentViewController 方法。我初始化一个 UIViewController ,添加我的自定义模式查看作为 UIViewController的子视图,然后可选择使用约束来定位模态查看。像魅力一样!

My new solution uses the standard presentViewController method of a UIViewController. I initialize a UIViewController, add my custom modal View as a subview of the UIViewController, and then optionally position the modal View using constraints. Works like a charm!

原始答案

根据Anna的建议,我使用 UIWindow 而不是 UIView来实现它。这是我的新代码:

Following Anna's advice, I got it working by using a UIWindow instead of a UIView. Here's my new code:

var modalWindow:UIWindow = UIWindow(frame: self.view.window!.bounds)

modalWindow.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.66)
modalWindow.hidden = false
modalWindow.windowLevel = (UIWindowLevelStatusBar + 1)

modalWindow.addSubview(customView)    

modalWindow.makeKeyAndVisible()

它现在完全像之前,除了Apple状态栏上的文字也变暗了。非常感谢您的帮助!

It now works exactly as before, except the text on the Apple status bar gets dimmed as well. Thank you very much for all of the help!

这篇关于在iOS 8中显示Apple Status Bar上方的UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆