UICollectionViewCell to UIButton Focus in tvOS

后端 未结 5 808
野的像风
野的像风 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 22:46

    Swift 3.0

    Jess Bower's answer was huge help to me & saved a lot of time.

    Here's what worked with Swift 3 & tvOS 10. One now has to use preferredFocusEnvironments. In ViewDidLoad()

            self.view.addLayoutGuide(focusGuide)
            self.focusGuide.topAnchor.constraint(equalTo: self.buttonAbove.topAnchor).isActive = true
            self.focusGuide.bottomAnchor.constraint(equalTo: self.CollectionView.topAnchor).isActive = true
            self.focusGuide.leadingAnchor.constraint(equalTo: self.CollectionView.leadingAnchor).isActive = true
            self.focusGuide.widthAnchor.constraint(equalTo: self.CollectionView.widthAnchor).isActive = true
            self.focusGuide.preferredFocusEnvironments = [self.buttonAbove]
    

提交回复
热议问题