I use a standard
UICollectionView
with sections. My cells are laid out like a grid. The next cell in a chosen direction is correctly focused if the user moves the focus around with the Apple TV remote. But if there is a "gap" in the grid, the default focus engine jumps over sections. It does this to focus a cell which could be several sections away but is in the same column.Example: There are 3 sections. The first section has 3 cells. The second has 2 cells and the last one has 3 cells again. See the following image:
http://i.stack.imgur.com/ums8b.png
If the green cell is focused and the user touches the down direction, the yellow cell gets focused and section two is skipped by the focus engine.
I would like to force it that no sections can get jumped over. So instead of focusing the yellow cell I would like to focus the blue cell.
I looked into the delegate methods in
UICollectionViewDelegate
like shouldUpdateFocusInContext:
which informs the delegate about the focus update. But that delegate method only allows to disable the focus update and not change it to an other cell. I also played around with canFocusItemAtIndexPath:
but was not able to achieve the desired behaviour.There seems to be no other delegate method which could do that. Is there an other way?
There is no direct hook into UICollectionView for accomplishing this, so you'll have to manage the layout yourself. You could add the focus guide on top of cells or supplementary/decoration views to piggyback on the collection view's layout system, or you could add the focus guide to the collection view itself and update its layout whenever the collection view finishes layout, based on the new position of the cells.
Also, we would definitely be interested in any suggestions you may for improving the SDK. Feel free to file feature requests at bugreporter.apple.com.