I have been trying to focus the first button but focus engine takes the third button right below the tab bar as the first item to be focussed. I tried with preferred focus view but found that when i place the buttons in vertical order then preferred takes the preferred view to be focussed but when i placed all the buttons in horizontal plane it always takes the third button.The other approach i can think of if Focus Guide but i wonder how that will work in this scenario?
 override weak var preferredFocusedView: UIView? {
        get {
            return thrirdButton
        }
    }
It happens because focus engine takes the nearest possible focus element as 1st element as you can see from the picture attached.I have attached the context screenshot for the view controller. Any help or clue to solve this will be appreciated.
 

Solution : We need to add focus guide just above button 3 and redirect it to button one when the focus guide is focussed.
private var focusGuide = UIFocusGuide()
self.view.addLayoutGuide(focusGuide)
    self.focusGuide.bottomAnchor.constraintEqualToAnchor(self.button3.topAnchor).active = true
    self.focusGuide.leftAnchor.constraintEqualToAnchor(self.button3.leftAnchor).active = true
    // Width and height
    self.focusGuide.widthAnchor.constraintEqualToAnchor(self.button3.widthAnchor).active = true
    self.focusGuide.heightAnchor.constraintEqualToAnchor(self.button3.heightAnchor).active = true
    focusGuide.centerXAnchor.constraintEqualToAnchor(self.button3.centerXAnchor).active = true
  override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
        self.focusGuide.preferredFocusedView = button1
    }

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With