8

我最喜欢的 iOS 隐藏调试工具之一是recursiveDescriptionUIView实例上使用。例如,这对于排除可能不在屏幕上的视图位置非常有用。在 tvOS 上调试 Focus Engine 会带来一系列挑战,尤其是围绕它认为的可聚焦元素。

tvOS 是否有任何隐藏的调试工具来内省 Focus Engine 内部的情况?

4

2 回答 2

16

有两种有用的方法,这两种方法实际上都记录在tvOS 的 App Programming Guide 中

界面视图

如果您试图将焦点移至特定视图但不能,则有一种调试方法UIView可以帮助解释原因:_whyIsThisViewNotFocusable

此方法的输出如下所示:

(lldb) po [(UIView *)0x148db5234 _whyIsThisViewNotFocusable]
ISSUE: This view has userInteractionEnabled set to NO. Views must allow user interaction to be focusable.
ISSUE: This view returns NO from -canBecomeFocused.

UIFocusUpdateContext

UIFocusUpdateContext对象支持 Xcode 的 QuickLook 功能,因此如果您在调试器中暂停,您可以按空格键(或单击变量旁边的眼球图标)以查看焦点引擎所看到的图形表示(图像来自 Apple 的文档):

焦点更新上下文的 QuickLook 示例

于 2015-09-28T20:17:46.903 回答
2

从 tvOS 11 开始,解决无法访问的项目变得更加容易,只需将其添加到问题中 ViewController 的 viewDidLoad 中:

 if #available(tvOS 11.0, *) {
  NotificationCenter.default.addObserver(
    forName: NSNotification.Name.UIFocusMovementDidFail
  ) { [weak self] notification in
    let context = notification.userInfo![UIFocusUpdateContextKey] as! UIFocusUpdateContext
    print(context) // If you add a breakpoint here you can quicklook the context in the debugger for more information
    print(UIFocusDebugger.checkFocusability(for: self!.collectionView)) // replace collectionView with the view you want to check
  }
}

这会产生如下调试输出:

<UIFocusUpdateContext: 0x6080000fe800: previouslyFocusedItem=<UIKeyboard 0x7fc597d75610>, nextFocusedItem=(null), focusHeading=Down>

The following issues were found that would prevent this item from being focusable:
- ISSUE: The item is being visually occluded by the following items:
<UIView 0x7fc597c3a9e0>
于 2018-03-22T08:57:02.193 回答