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

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

问题描述

我想要创建一个视图(UIControl),该视图会在验证用户时阻止所有输入并显示UIActivityIndi​​catorView。

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

UIActionSheet和U​​IAlertView都可以添加一个黑色的半透明视图在所有其他视图的顶部阻止输入,我想做类似。

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.

我已经尝试添加我的视图到顶部UIWindow在[[UIApplication sharedApplication] windows]数组中,虽然这将它放在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作为子视图。这个效果很好,但是当你调用UIAlertViewshow的时候,我似乎不能杀掉默认的bouncy转换。

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.

推荐答案

我会向用户表明他们的行动必须完成,

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.

请注意,苹果不鼓励,但也不允许创建多个窗口。

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,包括StatusBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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