iPhone iPad是否可以通过编程方式完全禁用屏幕交互和手势?

时间:2020-12-27 22:51:35

I built an ios game for my cat and he's quite fond of it. However, when he touches the screen , he repeatedly invokes all kinds of gestures - notification center, pinch to home screen, swipe between apps. I have to sit next to him and "fix" the game continuously, which defeats the purpose of an automatic game. I tried disabling gestures them in preferences, but the cat still manages to get out of the app.

我为我的猫设计了一个ios游戏,他很喜欢。然而,当他触摸屏幕时,他会反复地调用各种手势——通知中心,缩放到主屏幕,在应用程序之间滑动。我不得不坐在他旁边,不停地“修理”游戏,这就违背了自动游戏的目的。我试着在设置中禁用它们的手势,但这只猫还是成功地退出了应用程序。

Is it possible to "lock an iPhone" with screen on programmatically on vanilla iOS 7, so only the home button would exit the app?

是否可以在普通的iOS 7上以编程方式“锁定iPhone”,这样只有home按钮才能退出应用程序?

2 个解决方案

#1


2  

I know you have asked how to do it programmatically. However, there is already an accessibility feature for your problem.

我知道您已经问过如何以编程方式完成它。但是,您的问题已经有了一个可访问性特性。

Go to Settings > General > Accessibility. Enable Guided Access and set a password. Once it is enabled, open your app and triple-click the home button. Your cat won't be able to leave the app even by clicking the home button.

转到设置>一般>可访问性。启用引导访问并设置密码。启用后,打开应用程序,双击home按钮。你的猫甚至不能通过点击home键离开应用程序。

#2


2  

For ignoring interactions you can use following:

对于忽略交互,可以使用以下方法:

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

This tells the receiver to suspend the handling of touch-related events. Here receiver is the Application object.

这告诉接收者暂停处理与触摸相关的事件。这里接收者是应用程序对象。

and for enable interactions again use:

对于使能交互再次使用:

[[UIApplication sharedApplication] endIgnoringInteractionEvents];

This tells the receiver to resume the handling of touch-related events.

这告诉接收者继续处理与触摸相关的事件。

#1


2  

I know you have asked how to do it programmatically. However, there is already an accessibility feature for your problem.

我知道您已经问过如何以编程方式完成它。但是,您的问题已经有了一个可访问性特性。

Go to Settings > General > Accessibility. Enable Guided Access and set a password. Once it is enabled, open your app and triple-click the home button. Your cat won't be able to leave the app even by clicking the home button.

转到设置>一般>可访问性。启用引导访问并设置密码。启用后,打开应用程序,双击home按钮。你的猫甚至不能通过点击home键离开应用程序。

#2


2  

For ignoring interactions you can use following:

对于忽略交互,可以使用以下方法:

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

This tells the receiver to suspend the handling of touch-related events. Here receiver is the Application object.

这告诉接收者暂停处理与触摸相关的事件。这里接收者是应用程序对象。

and for enable interactions again use:

对于使能交互再次使用:

[[UIApplication sharedApplication] endIgnoringInteractionEvents];

This tells the receiver to resume the handling of touch-related events.

这告诉接收者继续处理与触摸相关的事件。