The basic idea of the solution described below is to subclass UITabBarController
and selectively use the super
implementation of weak var preferredFocusedView: UIView? { get }
or one that returns selectedViewController?.preferredFocusView
along with an implementation of didUpdateFocusInContext(_:withAnimationCoordinator:)
that sets up an NSTimer
that triggers a focus update and sets a flag that controls the preferredFocusView
implementation.
More verbosely, Subclass UITabBarController
and override didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator)
. In your implementation (make sure to call the super
implementation) you can inspect the context and determine if a descendent view of the tabBar
property is the nextFocusedView
or the previousFocusedView
(and the nextFocusedView
is not a descendent).
If the tab bar is gaining focus you can create an NSTimer
for the duration that you want to show the tab bar before hiding it. If the tab bar loses focus before the timer fires, invalidate it. If the timer fires, call setNeedsFocusUpdate()
followed by updateFocusIfNeeded()
.
The last piece you need to get this to work is a flag that is set to true
while the timer is set. You then need to override weak var preferredFocusedView: UIView? { get }
and call the super
implementation if the flag is false
and if it is true
return selectedViewController?.preferredFocusedView
.