UICollectionViewCell到UIButton专注于tvOS [英] UICollectionViewCell to UIButton Focus in tvOS

查看:235
本文介绍了UICollectionViewCell到UIButton专注于tvOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UICollectionView,它包含12-13个UICollectionViewCells。我可以轻松专注于UICollectionViewCells,一切正常。 UICollectionView外面有一个UIButton。如果我在第一个细胞或第二个细胞上,我向上滑动,那么我可以轻松地专注于UIButton。当我在第三个单元格上时,我无法将焦点移动到UIButton。有什么想法发生了什么?

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 UICollectionView. If I am on the first cell or the second cell and I swipe up then I can easily focus on the UIButton. When I am on the third cell then I am not able to move the focus to the UIButton. Any ideas what is going on?

推荐答案

您应该使用包含您想要聚焦的UIButton的UIFocusGuide。使UIFocusGuide与collectionView一样宽,并且足够高以覆盖按钮。使preferredFocusView成为按钮。

You should use a UIFocusGuide that encompasses the UIButton you want to focus. Make the UIFocusGuide as wide as the collectionView and tall enough to cover the button. Make the preferredFocusView the button.

  UIFocusGuide *topButtonFocusGuide = [[UIFocusGuide alloc] init];
  topButtonFocusGuide.preferredFocusedView = myButton;
  [self.view addLayoutGuide:topButtonFocusGuide];

  [self.view addConstraints:@[
    [topButtonFocusGuide.topAnchor constraintEqualToAnchor:myButton.topAnchor],
    [topButtonFocusGuide.bottomAnchor constraintEqualToAnchor:myCollectionView.topAnchor],
    [topButtonFocusGuide.leadingAnchor constraintEqualToAnchor:myCollectionView.leadingAnchor],
    [topButtonFocusGuide.widthAnchor constraintEqualToAnchor:myCollectionView.widthAnchor],
  ]];

这篇关于UICollectionViewCell到UIButton专注于tvOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆