I'm looking for a way to make a custom transition when changing the focus from or to the UITabBar.
I'm currently trying this by overriding the didUpdateFocus method but I seem to be unable to check if the the tabBar is focused.
The tabBar itself seem to never be in the "focused" state:
override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinatora)
{
super.didUpdateFocus(in: context, with: coordinator)
print(self.tabBar.isFocused) // always false
}
When checking the UIFocusUpdateContext the currently focused element is a UITabBarButton.
But I'm unable to check if the context is an instance of UITabBarButton because that type isn't available:
context.nextFocusedItem is UITabBarButton // can't compile
I'm really stuck here and would love any suggestions on how to tackle this one.
Thanks.
I have created extension on UIView which will check if there is focus somewhere in its hierarchy:
This way you can check if your UITabBar has focus.
Note:
This is very expensive way of checking if your view has focus, because it is recursive function and it will potentially traverse the whole hierarchy of your view.
Tip:
If you are trying to implement custom transition when selecting tabs in UITabBar you should use UITabBarDelegate method:
If not, just ignore this tip.