UIButton at different levels of Y cannot be focused on tvOS

I started developing apps for Apple TV, and I have this problem with buttons. I have a screen where there are several buttons at the bottom of the screen, and then there is one that is in the middle (see Screenshot to understand). The problem is that I cannot concentrate on the middle button. Focus is only on the bottom three buttons. Obviously, the problem is related to the Y-position , when I move the button at the bottom of the screen, it focuses.

Buttons are created in the storyboard, code is missing in the ViewController. The settings in the storyboard for the middle button are the same as the settings for the lower buttons. Should I handle this manually in code? Or is it possible to get such a focus movement? I would appreciate any information, thanks.

one]

I'm still developing in a simulator.

+8
tvos swift uibutton focus
source share
2 answers

So, I was guided by an apple for a solution. This requires a little coding using UIFocusGuide. For this, Apple has sample code .

+3
source share

Add a focus guide to fill in the missing space.

let focusGuide = UIFocusGuide() view.addLayoutGuide(focusGuide) focusGuide.widthAnchor.constraintEqualToAnchor(buttonThatIsFocused.widthAnchor).active = true focusGuide.leftAnchor.constraintEqualToAnchor(buttonThatIsFocused.leftAnchor).active = true focusGuide.heightAnchor.constraintEqualToAnchor(buttonTryingToFocus).active = true focusGuide.preferredFocusedView = buttonTryingToFocus 
0
source share

All Articles