In my app, a lock screen is used. Sometimes a UIAlertView
is shown, now when the user sends the app to the background and brings it in front again, the UIAlertview
is shown above the lock screen. Is there a possibility to add a UIViewController
's view above everything, i.e. above the UIAlertView
?
Asked
Active
Viewed 2,509 times
3

swalkner
- 16,679
- 31
- 123
- 210
-
Smiler sort of problem to what you need to do, so I hope it helps. https://stackoverflow.com/questions/22241412/add-uiview-banner-above-status-bar-ios-7 – BooRanger Jun 17 '14 at 11:47
-
One way to sidestep the problem might be to maintain a reference of your `UIAlertView`, and hide it when the app enters the background. When the app enters the foreground again, it's up to you to decide what you do with the alertView reference. – Vinod Vishwanath Jun 17 '14 at 11:48
-
Good question. But I think `UIAlertView` is supposed to be on top of everything - that's its duty - to alert. – Unheilig Jun 17 '14 at 12:00
2 Answers
5
You should have like this
UIWindow *mySpecialWindowForLockScreen = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
//"Hey iOS Please put this window above all alert view"
mySpecialWindowForLockScreen.windowLevel = UIWindowLevelAlert+100;
UIViewController *lockScreenViewController = [[UIViewController alloc]init];//Lock Screen
lockScreenViewController.view.frame = mySpecialWindowForLockScreen.bounds;
mySpecialWindowForLockScreen.rootViewController = lockScreenViewController;
// In lockScreenViewController view you can add lock screen images and other UI stuff
mySpecialWindowForLockScreen.rootViewController.view.backgroundColor = [UIColor greenColor];
[mySpecialWindowForLockScreen makeKeyAndVisible];
Whenever you want to hide the LockScreen window then simply hide it by setHidden:YES.

Vijay-Apple-Dev.blogspot.com
- 25,682
- 7
- 67
- 76
-
now it works for me as well; the problem was that ARC cleaned up the ```mySpecialWindowForLockScreen``` immediately, therefore I had to make a property for it. – swalkner Jun 18 '14 at 11:29
2
There are three kind of UIWindowLevel, the biggest one will be shown above the other window.
So I suggest you use a UIWindow to create your lock screen and let it's window level bigger than UIWindowLevelAlert
,
Basically, their values are :
UIWindowLevelNormal = 0.000000;
UIWindowLevel UIWindowLevelAlert = 2000.000000;
UIWindowLevel UIWindowLevelStatusBar = 1000.000000;
so that's why the alert view will show above the other window.have a try.

johnMa
- 3,291
- 24
- 37