I have a collection view with image cells that would like to have together without any space. The idea was to have the focused item float over all other cells.
I've implemented the code below, yet when a cell is focused, it doesn't necessarily float above all other cells. It's a really weird effect where other cells sometimes are still above the focused item.
#pragma mark - Focus Engine
- (NSIndexPath *)indexPathForPreferredFocusedViewInCollectionView:(UICollectionView *)collectionView {
return [NSIndexPath indexPathForItem:0 inSection:0];
}
- (BOOL)collectionView:(UICollectionView *)collectionView canFocusItemAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (BOOL)collectionView:(UICollectionView *)collectionView shouldUpdateFocusInContext:(UICollectionViewFocusUpdateContext *)context {
return YES;
}
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSArray *indexPaths = [collectionView indexPathsForSelectedItems];
NSIndexPath *selectedIndexPath = indexPaths.firstObject;
if (selectedIndexPath) {
[collectionView deselectItemAtIndexPath:selectedIndexPath animated:YES];
return NO;
}
else {
return YES;
}
}
On the storyboard, each cell is a subclass of UICollectionViewCell and each has an image view occupying the cell's entire content area. The following options are set up as follows in the storyboard's image views:
*Adjusts image when focused = ON
*Clip Subviews = OFF
So is it possible to force the focused item to float over all other views?