views:

46

answers:

1

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 technical implementation of such a solution.

A: 

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.

Costique
Thanks Constique. Your response gave me the critical clue of using UIWindowLevelStatusBar. After doing a bit more searching around StackOverflow using that keyword I found some sample code which works perfectly - http://stackoverflow.com/questions/2666792/add-uiview-above-all-other-views-including-statusbar . Hope that this is useful to others also looking to achieve the same thing.
Skoota