1

I have a wide "dock" area at the bottom of the screen. I have placed a UIFocusGuide across the top of it. Depending on which element in the dock has focus, the system may or may not have a focus solution if the user swipes up.

How can I tell my focus guide to use the system-calculated new focus item if there is one, but if not, it should use the one configured in my setPreferredFocusEnvironments:

Alternatively, is there a way to determine where a "swipe up" will take the focus without actually doing it? As the focused element in the dock changes, I could check this and if it has no destination provided by the system, I can add one.

My dock is a view within a main view controller but preferredFocusEnvironments is never called when the user tries to move to a non-existent view from an element in the dock.

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
Trygve
  • 1,317
  • 10
  • 27
  • Can you provide the code of your focus logic you already have? `preferredFocusEnvironments` alone won't give you enough information. You'll most likely need a `Bool` flag and override `shouldUpdateFocus(in:)` to include some additional logic. https://developer.apple.com/documentation/uikit/uifocusenvironment/1616831-shouldupdatefocus – Daniel Storm Jun 10 '20 at 00:41
  • I overrode `preferredFocusEnvironments` and was hoping that if a swipe up occurred it would call this method and I could somehow check if the system could determine a place to move the focus too. If not, I would provide one. However `preferredFocusEnvironments` is never called when a slide-up-to-nowhere event happens. I can make it work with a `UIFocusGuide` but I only want this custom-forward to happen if the system has no other option. A `UIFocusGuide` is really what makes sense here, but I first want to see if the system can figure out the natural place to move the focus. – Trygve Jun 10 '20 at 00:49

0 Answers0