且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我们如何检测iOS 7上的控制中心?

更新时间:2023-02-03 09:56:35

我刚刚发布了一个小UIWindow子类这正是如此。您只需订阅NSNotification并可以对打开控制中心的用户做出反应。 Github上的详细说明和设置: AAWindow

I just published a little UIWindow subclass that does exactly that. You simply subscribe to an NSNotification and can react to the user opening Control Center. Detailed instructions and setup on Github: AAWindow.

实现这一目标的方法是在UIWindow中使用NSTimer和覆盖sendEvent的组合来接收所有触摸而不阻止它们。所以你基本上接收所有触摸检查它们是否接近屏幕的下边缘,如果是设置定时器半秒,并且如果在此定时器运行期间调用applicationWillResignActive,则几乎可以肯定ControlCenter已打开。如果没有状态栏,则时间必须变化,因为此时应用程序处于全屏状态,并且用户最多可以花3秒钟启动控制中心。

The way this is accomplished is by using a combination of NSTimer and overwriting sendEvent in UIWindow to receive all touches without blocking them. So you basically receive all touches check if they are near the lower edge of the screen, if yes set a timer for a half a second and if during this timer is running applicationWillResignActive is called you can be almost certain that ControlCenter is opened. The time has to vary if there's no statusbar, because then the app is in fullscreen and it can take the user up to 3 seconds to launch Control Center.