tvOS中是否有用于Focus Engine调试的隐藏工具?

时间:2015-09-28 16:11:05

标签: debugging tvos

我最喜欢的iOS隐藏调试工具之一是在recursiveDescription实例上使用UIView。例如,这对于对可能在屏幕外的视图位置进行故障排除非常有用。在tvOS上调试Focus Engine带来了一系列挑战,尤其是它认为可以集中精力的元素。

是否有针对tvOS的隐藏调试工具来内省Focus Engine内部的内容?

2 个答案:

答案 0 :(得分:14)

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

的UIView

如果您尝试将焦点移至特定视图但不能,则<security:intercept-url method="GET" pattern="/newapi/user/**" access="hasRole('ROLE_USER','LOW_ADMIN')" /> <security:intercept-url method="GET" pattern="/newapi/user/*/*" access="hasRole('ROLE_USER,'BIG_ADMIN')" /> 上的调试方法有助于解释原因:UIView

此方法的输出如下所示:

_whyIsThisViewNotFocusable

UIFocusUpdateContext

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

QuickLook example of focus update context

答案 1 :(得分:1)

自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>