在所有其他视图之上添加 UIView,包括状态栏 [英] Add UIView Above All Other Views, Including StatusBar

查看:24
本文介绍了在所有其他视图之上添加 UIView,包括状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个视图 (UIControl),它会在对用户进行身份验证时阻止所有输入并显示 UIActivityIndi​​catorView.

I'm wanting to create a view (UIControl) which blocks all input and shows a UIActivityIndicatorView while authenticating a user.

UIActionSheet 和 UIAlertView 都设法在所有其他视图的顶部添加一个黑色半透明视图来阻止输入,我想做类似的事情.

The UIActionSheet and UIAlertView both manage to add a black semi-transparent view over the top of all other views to block input and I'd like to do similar.

我已经尝试将我的视图添加到 [[UIApplication sharedApplication] windows] 数组中的顶部 UIWindow,虽然这确实将它放置在 UIKeyboard 上方(如果它可见),但它不会将它放置在 StatusBar 上方(这使得感觉).

I've tried adding my view to the top UIWindow in the [[UIApplication sharedApplication] windows] array, and while this does place it above the UIKeyboard if it's visible, it doesn't place it over the StatusBar (which makes sense).

我的下一次尝试是扩展 UIAlertView,删除它的所有子视图并设置它的 layer.contents = nil,然后将 ActivityIndi​​cator 添加为子视图.这很有效,但是当您将其调用为显示"时,我似乎无法终止 UIAlertView 的默认弹性过渡.

My next attempt was to extend UIAlertView, remove all of its subviews and set its layer.contents = nil, then add the ActivityIndicator as a subview. This works well, but I can't seem to kill the default bouncy transition of the UIAlertView when you call it to "show".

有没有人对解决这个问题的最佳方法有任何指示,让我完全控制?

Does anyone have any pointers towards the best way tackle this problem that gives me full control?

哦,我知道阻止输入不是很好,但我确实确保它是短时间的,它的好处是让用户清楚他们的动作(必须完成才能继续进行)正在处理.

Oh and I know blocking input is not great but I do ensure it's for a short period of time and it has the benefit of making it clear to the user that their action, which must complete for them to progress, is processing.

推荐答案

我已经对 API 进行了更多的挖掘,相信我已经解决了.

I've done some more digging around the API's and believe I've worked it out.

为了在整个屏幕上显示视图,您需要创建自己的 UIWindow 并将其 windowLevel 属性设置为 UIWindowLevelStatusBar.然后,您可以将自定义子视图添加到此窗口.

In order to display a view over the entire screen you need to create your own UIWindow and set its windowLevel property to be UIWindowLevelStatusBar. You can then add your custom subviews to this window.

请注意,Apple 不鼓励,但也不禁止创建多个窗口.

UIWindow *statusWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
statusWindow.windowLevel = UIWindowLevelStatusBar;
statusWindow.hidden = NO;
statusWindow.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
[statusWindow makeKeyAndVisible];

当你想从屏幕上移除窗口时,它看起来就像你从内存中释放它一样.

When you want to remove the window from the screen it looks as though you release it from memory.

[statusWindow release];

这感觉并不完全安全,但我没有收到任何错误,而且似乎将其从 UIApplication 的 windows 数组中删除.如果这是错误的,请告诉我.

This doesn't feel totally safe, but I don't get any errors and it seems to drop it out of the UIApplication's windows array. Please let me know if this is wrong.

更新:

我遇到的另一个问题是 UIStatusBar 在我显示并删除了这个覆盖窗口后,没有采取触摸事件将活动的 UIScrollView 滚动到顶部.解决方案是在覆盖层释放后将主窗口设置回关键窗口.

One other issue I came across was the UIStatusBar not taking touch events to scroll the active UIScrollView to the top after I had displayed and removed this overlay window. The solution was to set the primary window back to the key window once the overlay had been released.

[primaryWindow makeKeyWindow];

这篇关于在所有其他视图之上添加 UIView,包括状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆