开发者

UIView to cover iPhone status/carrier bar

I am attempting to create a UIView (and associated UIViewController) which mimic the behaviour of UIAlertView. Given my requirements it seemed much neater to create my own implementation from scratch than attempt to subclass and modify UIAlertView. In order to do this I am getting a reference to the app delegate and then adding the UIViewController.view (with an alpha of around 0.6) as a subview of the main app window. This means it will appear on top of all other views on screen and emulate the dimmed background found in the UIAlertView.

All is working well, except the UIView (i.e. UIViewController.view) is not covering the status/carrier bar at the top of the screen. This means that all of the screen is dimmed except the carrier bar, which looks a bit strange! Is there any way to get the UIView to appear on top of the carrier bar? I have heard musings about adding a second UIWindow to the app, but this does not seem advisible (as the Apple docs say that you should only ever have one UIWindow in the app) and, even if this is the best solution, I am unsure about the techni开发者_运维知识库cal implementation of such a solution.


In order to cover the status bar without hiding it you need something to be above the status bar, and since the status bar is displayed in another window, you have to use a second window with UIWindowLevelStatusBar.

I've done such a thing, it does work, but it feels like a hack, thanks to Apple's docs, or the lack thereof. You create a second window just as usual. To hide it you should both set its hidden property and release it. To make sure you're not leaking windows I recommend subclassing UIWindow for debugging sake and overriding its dealloc to include NSLog. Also, look at the UIApplication's windows property, it should reflect window closing properly.

The biggest pain in the rear is device orientation changes, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜