Skip to content

Instantly share code, notes, and snippets.

@bachand
Created September 10, 2015 20:45
Show Gist options
  • Save bachand/40bf0c5aad573845caca to your computer and use it in GitHub Desktop.
Save bachand/40bf0c5aad573845caca to your computer and use it in GitHub Desktop.
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