【发布时间】:2016-04-08 03:55:49
【问题描述】:
我目前正在为 tvOS 开发,我添加了一个 UISegmentedControl,它会由 tvOS 焦点引擎自动聚焦。当我添加了UIButton 时,这成为了第一个焦点项目。
如何设置第一个焦点项目并在它们之间导航?
【问题讨论】:
标签: uibutton uisegmentedcontrol tvos apple-tv
我目前正在为 tvOS 开发,我添加了一个 UISegmentedControl,它会由 tvOS 焦点引擎自动聚焦。当我添加了UIButton 时,这成为了第一个焦点项目。
如何设置第一个焦点项目并在它们之间导航?
【问题讨论】:
标签: uibutton uisegmentedcontrol tvos apple-tv
向您的视图控制器添加一个只读的preferredFocusedView 属性,该属性返回您想要开始聚焦的视图:
override weak var preferredFocusedView: UIView? {
get {
return segmentedControl
}
}
【讨论】:
UISegmentedControl,我想“滑动”到UIButton?
UIFocusGuide上找到了一个教程,但我得到了意想不到的结果。设置 focusGuide layoutAnchors 时,UIFocusGuide 立即放置在我的 UISegmentedControl 的右侧。但它应该正好在 UISegmentedControl 下方和我的 UIButton 的右侧。
self.view.addLayoutGuide(focusGuide)self.focusGuide.leftAnchor.constraintEqualToAnchor(self.choirSwitch.leftAnchor).active = trueself.focusGuide.topAnchor.constraintEqualToAnchor(self.playButton.topAnchor).active = trueself.focusGuide.widthAnchor.constraintEqualToAnchor(self.choirSwitch.widthAnchor).active = trueself.focusGuide.heightAnchor.constraintEqualToAnchor(self.playButton.heightAnchor).active = true