How can I force focus to change to a specific view in tvOS?

后端 未结 6 2290
Happy的楠姐
Happy的楠姐 2021-02-19 15:51

I am implementing custom code to handle a click on the Menu button on the Siri Remote. How can I force focus to change to my custom menu when pressing the menu button?

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-19 16:42

    For ios 10 you should use preferredFocusEnvironments instead of preferredFocusedView .

    In below example if you want to focus on button then see below code.

    @IBOutlet weak var button: UIButton!
    
    override var preferredFocusEnvironments: [UIFocusEnvironment] {
        return [button]
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        setNeedsFocusUpdate()
        updateFocusIfNeeded()
    }
    

提交回复
热议问题