我目前正在开发 Apple TV 应用程序。我的视图是这样从左到右建立的(另见截图)
- 小的
UICollectionView
UIImageview
UIView
UILabels
UIButton
UIButton
当我在第二个时,我只能把注意力集中在右边uicollectionviewCell
。
当我在第一个和第三个单元格时,我无法将焦点转移到UIButton
.
对此有什么帮助吗?
编辑
我有这个代码在我的ViewDidLoad
view.addLayoutGuide(focusGuide)
focusGuide.leftAnchor.constraintEqualToAnchor(collectionView.leftAnchor).active = true
focusGuide.topAnchor.constraintEqualToAnchor(collectionView.topAnchor).active = true
focusGuide.widthAnchor.constraintEqualToAnchor(view.widthAnchor).active = true
focusGuide.heightAnchor.constraintEqualToAnchor(view.heightAnchor).active = true
并添加了这个方法:
override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
super.didUpdateFocusInContext(context, withAnimationCoordinator: coordinator)
guard let nextFocusedView = context.nextFocusedView else { return }
switch nextFocusedView {
case self.collectionView:
self.focusGuide.preferredFocusedView = self.orderButton
case self.orderButton:
self.focusGuide.preferredFocusedView = self.collectionView
default:
self.focusGuide.preferredFocusedView = nil
}
}