iOS 用の隠しデバッグ ツールの中で私のお気に入りの 1 つは、インスタンスでの使用recursiveDescription
ですUIView
。これは、たとえば、画面外にある可能性のあるビューの場所のトラブルシューティングに非常に役立ちます。tvOS でフォーカス エンジンをデバッグすると、特にフォーカス可能な要素と見なされるものに関して、独自の一連の課題が発生します。
Focus Engine 内で何が起こっているかを調べるための tvOS 用の隠しデバッグ ツールはありますか?
2 つの便利な方法があり、どちらもtvOS のアプリ プログラミング ガイドに実際に記載されています。
フォーカスを特定のビューに移動しようとしても移動できない場合は、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
オブジェクトは Xcode の QuickLook 機能をサポートしているため、デバッガーで一時停止している場合は、スペースバーを押す (または変数の横にある目玉アイコンをクリックする) と、フォーカス エンジンが見ているものをグラフィカルに表示できます (画像は Apple のドキュメントからのものです)。
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>