UICollectionViewCell to UIButton Focus in tvOS

后端 未结 5 797
野的像风
野的像风 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 23:04

    Jess Bowers solution is almost there but Xcode says UIButtons doesn't have topAnchor property and the solution given by Jess doesn't work for me.

    For me, the solution was to create a huge view with the same width as the UICollectionView on top of it. See picture.

    The code will be this:

     UIFocusGuide *topButtonFocusGuide = [[UIFocusGuide alloc] init];
      topButtonFocusGuide.preferredFocusedView = myButton;
      [self.view addLayoutGuide:topButtonFocusGuide];
    
      [self.view addConstraints:@[
        [topButtonFocusGuide.topAnchor constraintEqualToAnchor:transparentView.topAnchor],
        [topButtonFocusGuide.bottomAnchor constraintEqualToAnchor:transparentView.bottomAnchor],
        [topButtonFocusGuide.leadingAnchor constraintEqualToAnchor:transparentView.leadingAnchor],
        [topButtonFocusGuide.widthAnchor constraintEqualToAnchor:transparentView.widthAnchor],
      ]];
    

提交回复
热议问题