so I am exploring the new tvOS. As I wanted to kind of replicate the horizontal feature section of the app store (e.g. "Best New Apps")
所以我正在探索新的tvOS。因为我想要复制应用商店的水平功能部分(例如“最佳新应用”)
My plan was to use a UITableView to lay out the base structure (rows) and use an UICollectionView for all the individual horizontally scrollable items.
我的计划是使用UITableView来布局基本结构(行),并为所有单独的可水平滚动项使用UICollectionView。
Unfortunately the tvOS always focuses the UITableViewCell, not the UICollectionViewCell inside. I've already read about the
不幸的是,tvOS始终关注UITableViewCell,而不是内部的UICollectionViewCell。我已经读过了
override var preferredFocusedView: UIView? {
return aView
}
So using this inside my controller is kind of hard regarding getting the correct subview.
所以在我的控制器中使用这个在获得正确的子视图方面有点困难。
Is there anything I could look into or could someone please point me in the right direction? Iterating through all subviews until I get the correct one seems like a bad idea.
有什么我可以研究或有人请指出我正确的方向?迭代所有子视图,直到我得到正确的视图似乎是一个坏主意。
Thanks a lot!
非常感谢!
2 个解决方案
#1
15
I tried out a similar situation where I had a CollectionView within a CollectionView to get the setup you described. Let's call them innerCV and outerCV. To get innerCV to be focused and not outerCV's cells, I set this delegate method to return false for outerCV.
我尝试了类似的情况,我在CollectionView中有一个CollectionView来获取你描述的设置。我们称它们为innerCV和outerCV。为了使innerCV成为焦点而不是outerCV的单元格,我将此委托方法设置为为outerCV返回false。
- (BOOL)collectionView:(UICollectionView *)collectionView canFocusItemAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
In turn, innerCV's cells are now focusable as opposed to outerCV's cells.
反过来,innerCV的细胞现在可以聚焦,而不是outerCV的细胞。
Credit for this goes to Apple. I used their sample project as a guide to start. Check out the Focus samples within their project.
归功于Apple。我用他们的示例项目作为入门指南。查看项目中的焦点样本。
Sample Project: Apple tvOS UIKitCatalog
示例项目:Apple tvOS UIKitCatalog
#2
1
I used a different approach..
我用了不同的方法..
Setting the tableview selection
property to No Selection
in storyboard makes the focus engine to focus on UICollectionViewCell cell rather than UITableViewCell.
在storyboard中将tableview选择属性设置为No Selection,使焦点引擎专注于UICollectionViewCell单元而不是UITableViewCell。
Hope it helps :)
希望能帮助到你 :)
图片
#1
15
I tried out a similar situation where I had a CollectionView within a CollectionView to get the setup you described. Let's call them innerCV and outerCV. To get innerCV to be focused and not outerCV's cells, I set this delegate method to return false for outerCV.
我尝试了类似的情况,我在CollectionView中有一个CollectionView来获取你描述的设置。我们称它们为innerCV和outerCV。为了使innerCV成为焦点而不是outerCV的单元格,我将此委托方法设置为为outerCV返回false。
- (BOOL)collectionView:(UICollectionView *)collectionView canFocusItemAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
In turn, innerCV's cells are now focusable as opposed to outerCV's cells.
反过来,innerCV的细胞现在可以聚焦,而不是outerCV的细胞。
Credit for this goes to Apple. I used their sample project as a guide to start. Check out the Focus samples within their project.
归功于Apple。我用他们的示例项目作为入门指南。查看项目中的焦点样本。
Sample Project: Apple tvOS UIKitCatalog
示例项目:Apple tvOS UIKitCatalog
#2
1
I used a different approach..
我用了不同的方法..
Setting the tableview selection
property to No Selection
in storyboard makes the focus engine to focus on UICollectionViewCell cell rather than UITableViewCell.
在storyboard中将tableview选择属性设置为No Selection,使焦点引擎专注于UICollectionViewCell单元而不是UITableViewCell。
Hope it helps :)
希望能帮助到你 :)
图片