Skip to content

Instantly share code, notes, and snippets.

@bachand
Created September 10, 2015 20:45
Disabling Focus in UICollectionView
func collectionView(collectionView: UICollectionView, shouldUpdateFocusInContext context: UICollectionViewFocusUpdateContext) -> Bool {
guard let indexPaths = collectionView.indexPathsForSelectedItems() else { return true }
return indexPaths.isEmpty
}
func collectionView(collectionView: UICollectionView, shouldSelectItemAtIndexPath indexPath: NSIndexPath) -> Bool {
if let indexPath = collectionView.indexPathsForSelectedItems()?.first {
collectionView.deselectItemAtIndexPath(indexPath, animated: true)
return false
}
else {
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment