Is it possible to disable Control Center in iOS 7 programmatically and if not, what are alternatives?

╄→гoц情女王★ 提交于 2019-11-26 08:12:57

问题


I have developed an app that uses swipe gesture from bottom up. It was working perfectly in iOS 6, but now iOS 7 came out, and it works maybe 1 out of 25 times: i get iOS 7 Control Center almost every time. Obviously, Control Center can be disabled in the Settings, but that is up to the phone owner, and I cannot control that. So my question is, is there a way to disable Control Center for the time when my app is running (or more likely, is \"active\", as I would want Control Center back if the user is not actively using my app). If not, what are the alternatives? Is relocating/reworking that functionality is the only solution?


回答1:


No alternatives, really. The best you can do is warn users and ask them to go to settings to turn it off.

Realistically, you'll lose a lot of users just by asking that, so you should change the gestures.




回答2:


Actually there is an option. You cannot disable it. But you can prevent the accidental launch. Just disable the status bar. Then on swipe the user will be prompted whether the control centre have to be launched or not. it won't be launched in a single swipe. Instead an arrow appears on the first swipe and the user need to click and drag the arrow to launch the control centre, hence prevent accidental launch. Use this code to disable status bar.

You can disable the status bar using this delegate in IOS7:

- (BOOL) prefersStatusBarHidden
{
    return YES;
} 

And this method in IOS6.1 and prior:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];



回答3:


Starting with the iOS 11 SDK (compiled in Xcode 9) additionally to implementing prefersStatusBarHidden:

Objective-C:

- (BOOL) prefersStatusBarHidden
{
    return YES;
} 

Swift 4+:

override var prefersStatusBarHidden: Bool { return true }

you also need to implement preferredScreenEdgesDeferringSystemGestures:

Objective-C:

- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures{
    return UIRectEdgeAll;
};

Swift 4+:

override func preferredScreenEdgesDeferringSystemGestures() -> UIRectEdge {
    return .all
}

Otherwise the Control/Notification Center appear directly; instead of first showing the gray box with a up/down arrow that needs to be dragged up/down.



来源:https://stackoverflow.com/questions/19306449/is-it-possible-to-disable-control-center-in-ios-7-programmatically-and-if-not-w

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