在UISplitViewController中更改默认焦点

时间:2017-02-02 22:44:43

标签: swift3 focus uisplitviewcontroller tvos

enter image description here在UISplitViewController中,默认情况下,焦点设置在TableView上。有没有办法让我覆盖它,以便重点关注DetailViewController?

启动应用程序时,我可以将焦点更改为按钮而不是TableView单元格吗?

1 个答案:

答案 0 :(得分:1)

找到解决方案:

override weak var preferredFocusEnvironments: [UIFocusEnvironment] {
    get {
        let controllerToFocus = viewControllers[1] as? ViewController
        return [(controllerToFocus?.view)]
}

我们需要调用setNeedsFocusUpdate()和updateFocusIfNeeded():

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(true)

    self.setNeedsFocusUpdate()
    self.updateFocusIfNeeded()
}