从iPhone X iOS 12的底部边缘向上滑动时,停止应用程序进入后台 [英] Stop app going to background when swiping up from bottom edge on iPhone X iOS 12
问题描述
在iPhone X iOS 12上从屏幕底部边缘滑动时,我的游戏进入了背景模式.
My game is going into background mode when performing a swipe from the bottom edge of the screen on iPhone X iOS 12.
按照 Apple文档覆盖setNeedsUpdateOfScreenEdgesDeferringSystemGestures
应该会阻止应用程序进入后台,但这在iOS 12上不起作用.
As per Apple documentation overriding preferredScreenEdgesDeferringSystemGestures
and calling setNeedsUpdateOfScreenEdgesDeferringSystemGestures
should stop the app from going to background but this is's not working on iOS 12.
我正在使用Unity3D,并且编辑器具有在边缘上延迟系统手势选项(根据apple文档实现),但也无法正常工作.
I am using Unity3D and the editor has the Defer system gestures on edges option , which is implemented as per apple documentation, but also does not work.
我正在Xcode 10中编译项目.
I am compiling the project in Xcode 10.
还有其他人有这个问题吗,您有解决办法吗?
Does anyone else have this problem and do you have a fix?
PS:我正在一个空的单视图iOS项目中对此进行测试,唯一添加的代码如下:
PS: I am testing this in an empty single view iOS project, the only added code is the following:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear: animated];
[self setNeedsUpdateOfHomeIndicatorAutoHidden];
[self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
}
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
return UIRectEdgeAll;
}
- (BOOL)prefersHomeIndicatorAutoHidden
{
return YES;
}
更新:事实证明,如果我使用快速实现,它会起作用.太糟糕了,我无法为Unity3D 2017生成的项目执行此操作.
Update: Turns out that if I use a swift implementation it works. Too bad I cannot do this for the Unity3D 2017 generated project.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 11.0, *){
setNeedsUpdateOfScreenEdgesDeferringSystemGestures()
}
}
override var preferredScreenEdgesDeferringSystemGestures: UIRectEdge{
return [.all];
}
}
推荐答案
删除prefersHomeIndicatorAutoHidden
使其也可以在Objective C中使用.
Removing prefersHomeIndicatorAutoHidden
makes it work in Objective C also.
这是可行的示例实现,适用于遇到相同问题的任何人:
This is the working example implementation, for anyone having the same problem:
- (void)viewDidLoad {
[super viewDidLoad];
if (@available(iOS 11.0, *)) {
[self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
}
}
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
return UIRectEdgeAll;
}
对于像我一样使用Unity3d的用户,只需从生成的Xcode项目中的UnityViewControllerBase + iOS.mm中删除以下方法即可:
And for those who, like me, are using Unity3d just delete the following method from UnityViewControllerBase+iOS.mm in the generated Xcode project:
- (BOOL)prefersHomeIndicatorAutoHidden
{
return YES;
}
这篇关于从iPhone X iOS 12的底部边缘向上滑动时,停止应用程序进入后台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!