UIView above UIAlertView

狂风中的少年 提交于 2019-12-14 03:49:14

问题


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?


回答1:


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.




回答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.



来源:https://stackoverflow.com/questions/24262649/uiview-above-uialertview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!