Created
May 12, 2021 08:48
-
-
Save marlonjames71/4110d5384dfbcabdb6c5495bf2220b4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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