Skip to content

Instantly share code, notes, and snippets.

@marlonjames71
Created May 12, 2021 08:48
Show Gist options
  • Save marlonjames71/4110d5384dfbcabdb6c5495bf2220b4b to your computer and use it in GitHub Desktop.
Save marlonjames71/4110d5384dfbcabdb6c5495bf2220b4b to your computer and use it in GitHub Desktop.
// For one dimensional array
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let item = mediaItems[indexPath.item]
let pagedMediaViewController = PagedMediaController(mediaItem: item, currentIndex: indexPath.item)
pagedMediaViewController.modalPresentationStyle = .overFullScreen
present(pagedMediaViewController, animated: true)
}
// In case you're dealing with a two dimensional array like I was dealing with since the collection view's items
// had sections
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let item = mediaItems[indexPath.section][indexPath.item]
let joinedItems = mediaItems.flatMap { $0 }
guard let currentIndexForPagedMediaVC = joinedItems.firstIndex(of: item) else { return }
let pagedMediaViewController = PagedMediaController(mediaItem: item, currentIndex: currentIndexForPagedMediaVC)
pagedMediaViewController.modalPresentationStyle = .overFullScreen
present(pagedMediaViewController, animated: true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment