ios - Apple TV 力聚焦另一种观点
<p><p>我正在开发 Apple TV 项目。该项目包含标签栏 ViewController ,通常在 Remote 上向上滑动时会出现标签栏,向下滑动时会隐藏。但是现在我扭转了这种行为,我想在向上滑动时强制关注另一个 View (通常关注标签栏)。有什么办法吗?谢谢你。 </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在您的 UIViewController 中,覆盖 <strong>shouldUpdateFocusInContext</strong>。如果您检测到向上导航到选项卡栏,请返回 false 以防止焦点到达选项卡栏。然后使用 <strong>preferredFocusEnvironments</strong> + <strong>setNeedsFocusUpdate</strong> 的组合将焦点重定向到其他地方:</p>
<pre><code>override func shouldUpdateFocus(in context: UIFocusUpdateContext) -> Bool {
if let nextView: UIView = context.nextFocusedView{
if ( context.focusHeading == .up &&nextView.isDescendant(of: tabBar) ){
changeFocusTo(myView)
return false
}
}
}
internal var viewToFocus: UIView?
func changeFocusTo(_ view:UIView? ){
viewToFocus = view
setNeedsFocusUpdate()
}
override var preferredFocusEnvironments: {
return viewToFocus != nil ? : super.preferredFocusEnvironments
}
</code></pre>
<p>这是自定义焦点更新的一种普遍有用的技术。另一种技术是使用 <strong>UIFocusGuide</strong>。您可以在选项卡栏下方插入焦点指南,或使用焦点指南围绕选项卡栏以重定向焦点。尽管焦点指南对于简单的情况很有用,但使用我所描述的技术,我通常会获得更好的结果。</p></p>
<p style="font-size: 20px;">关于ios - Apple TV 力聚焦另一种观点,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39954230/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39954230/
</a>
</p>
页:
[1]