UIView above UIAlertView

2019-07-07 03:44发布

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?

2条回答
神经病院院长
2楼-- · 2019-07-07 03:51

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.

查看更多
爷的心禁止访问
3楼-- · 2019-07-07 04:09

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.

查看更多
登录 后发表回答