我们如何检测 iOS 7 上的控制中心? [英] How do we detect when control center on iOS 7?

查看:30
本文介绍了我们如何检测 iOS 7 上的控制中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 iOS 7 上出现控制中心时遇到问题.基本上,当控制中心出现时会触发 applicationDidEnterBackground.

I am having an issue when the control center appears on iOS 7. Basically, the applicationDidEnterBackground is fired when the control center appears.

但是在我的方法中,我想检测它是否只是控制中心打开或通知中心,因为我会在该状态下以不同的方式对待 applicationDidEnterBackground.

However in my method, I would like to detect if it's just the control center opening or the notification center since I would treat the applicationDidEnterBackground differently in that state.

任何帮助将不胜感激.

推荐答案

我刚刚发布了一个小 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.

实现这一点的方法是结合使用 NSTimer 和覆盖 UIWindow 中的 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.

这篇关于我们如何检测 iOS 7 上的控制中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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