简体   繁体   English

焦点引擎在集合视图单元上不起作用

[英]Focus engine not working on collection view cell

Just started playing around with tvOS and I can't get the focus engine to work on my collection view. 刚刚开始使用tvOS,我无法在我的收藏夹视图上使用焦点引擎。 The focus works with just about every other UI element such as buttons and table views but not the collection view. 焦点几乎与所有其他UI元素(例如按钮和表视图)一起使用,但不适用于集合视图。

I've tried overriding the delegate canFocusItemAtIndexPath and setting the cell to cell.camBecomeFocused() but none of it is working. 我已经尝试重写委托canFocusItemAtIndexPath并将单元格设置为cell.camBecomeFocused()但都没有起作用。

Thanks guys 多谢你们

You should take a look at the preferredFocusedView method. 您应该看一下preferredFocusedView方法。

https://developer.apple.com/library/prerelease/tvos/documentation/UIKit/Reference/UIFocusEnvironment_Protocol/index.html#//apple_ref/occ/intfp/UIFocusEnvironment/preferredFocusedView https://developer.apple.com/library/prerelease/tvos/documentation/UIKit/Reference/UIFocusEnvironment_Protocol/index.html#//apple_ref/occ/intfp/UIFocusEnvironment/preferredFocusedView

You can add this to your Collection View Cell in order to specify what subview should get the focus when the cell is focused. 您可以将其添加到“集合视图”单元格中,以指定当单元格被聚焦时哪个子视图应该获得焦点。 For example: 例如:

- (UIView *)preferredFocusedView
{
    // In this case, there would be a UITextField hooked up as _myTextField_
    return self.myTextField;
}

Now when the Collection View Cell is focused, in this example, the Text Field will get the focus. 现在,在此示例中,当“集合视图”单元格成为焦点时,“文本字段”将成为焦点。

I had same issue that I could not focus the UICollectionView when reload. 我有一个相同的问题,即重新加载时我无法集中UICollectionView。 This solution fixed mine problem. 该解决方案解决了地雷问题。 As said as Apple engineer, there is not any focus for the UICollectionViewCells by default but your imageView can be set adjustsImageWhenAncestorFocused to YES makes appearance of the focus in the collectionViewCell. 正如苹果工程师所说,默认情况下,UICollectionViewCells没有任何焦点,但是可以将您的imageView设置为AdjustsImageWhenAncestorFocused为YES,从而使焦点出现在collectionViewCell中。

Here is the code. 这是代码。

cell.imageView.adjustsImageWhenAncestorFocused  = true

Also refer to this link. 另请参阅此链接。 https://forums.developer.apple.com/message/56262#56262 https://forums.developer.apple.com/message/56262#56262

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM