UICollectionViewCell to UIButton Focus in tvOS

后端 未结 5 806
野的像风
野的像风 2020-12-14 22:29

I have a UICollectionView which contains 12-13 UICollectionViewCells. I can easily focus on the UICollectionViewCells and everything works. There is a UIButton outside the U

5条回答
  •  生来不讨喜
    2020-12-14 23:08

    One of the issues I was facing involved using a UINavigationController for the landing pages to push detail ViewControllers onto the stack when an item is selected.

    I put a breakpoint inside the UIButton's canBecomeFocused override, and using this quick little extension asked the button why it is not focusable.

    extension UIView {
        func whyNotFucusable () {
            print(self.perform(Selector(("_whyIsThisViewNotFocusable"))).takeUnretainedValue())
        }
    }
    

    I kept receiving the following error trying to debug....

    ISSUE: This view may not be focusable because other views or focus guides are occluding it.
    

    First of all I looked up in the dictionary what the heck occluding meant....

    verb, formal, technical 
         - stop, close up, or obstruct (an opening, orifice, or passage).
    

    The question now was what view is obstructing my UIButton???

    I quickly unwrapped the UI in the visual debugger, and there was a clear view on top of my UIButtons. Inspecting the view I found out that Unlike iOS, where the nagivationBar has a default system background color, tvOS's implementation has a clear default color. I realized that I didn't hide the nav bar, and in return it was obstructing my buttons.

    I did the following, and it fixed all my issues :)

    navController.setNavigationBarHidden(true, animated: false)
    

    Hope this helps!!!

提交回复
热议问题