abs*_*ths 0 view ios swift iphone-x
我试图在 iPhone X 上模拟 home 指示器的行为,但不知道如何。在某些应用程序中,主页指示灯变暗,您必须滑动它才能激活正常行为。我在控制器中找到了一个隐藏指示器的选项,但这不是我要找的。例如,在 Clash Royale 和 Clash of Clans 中,home 指示灯变暗,然后当你向上滑动它时,指示灯变亮,如果你再次这样做,它会激活“home”。使用我发现的 API 隐藏指标真的只会让它表现得很奇怪。
这是我正在使用的 API,但它不像我在其他应用程序中看到的那样工作。启用自动隐藏后,指示器将消失,直到您滑动并立即调用主页操作。这不好,因为目的是防止无意中滑动到主屏幕:
override func prefersHomeIndicatorAutoHidden() -> Bool {
return true
}
Run Code Online (Sandbox Code Playgroud)
我更喜欢的行为是指示灯变暗,然后在您向上滑动(但不是回家)时激活(变亮),然后再次向上滑动以触发主页。这种行为在 Supercell 应用程序中是不变的,但可能不是内置行为。
为了查看差异,您可以查看其中一个 Supercell 应用程序(在 iPhone X 上),并查看仅设置属性的应用程序。
I researched the question more and finally found the answer in this article: iPhone X: Dealing with Home Indicator
Emphasis here (I changed .top to .bottom since that is where the home indicator lives):
override func preferredScreenEdgesDeferringSystemGestures() -> UIRectEdge {
return .top
}
Run Code Online (Sandbox Code Playgroud)
What that does is defer the home action until the user performs the gesture once to activate the home control, and then a second time to invoke home. Now that I have found this I (ironically) probably won't use it. I will probably just leave enough extra room at the bottom. My problem isn't with the gesture, but with the indicator covering my content (probably needs a UI update, but I don't have time for that now).
Hopefully, someone else will find this useful since this behavior is pretty cool but difficult to discover.