File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,28 @@ open class InfiniteCollectionView: UICollectionView {
5050 open func rotate( _ notification: Notification ) {
5151 setContentOffset ( CGPoint ( x: CGFloat ( pageIndex + indexOffset) * itemWidth, y: contentOffset. y) , animated: false )
5252 }
53+
54+ open override func selectItem( at indexPath: IndexPath ? , animated: Bool , scrollPosition: UICollectionViewScrollPosition ) {
55+
56+ // Correct the input IndexPath
57+ let correctedIndexPath = IndexPath ( row: correctedIndex ( indexPath!. item + indexOffset) , section: 0 ) ;
58+
59+ // Get the currently visible cell(s) - assumes a cell is visible
60+ guard let visibleCell = self . visibleCells. first else {
61+ return ; // Nothing to select...
62+ }
63+ // Index path of the cell - does not consider multiple cells on the screen at the same time
64+ var visibleIndexPath : IndexPath ! = self . indexPath ( for: visibleCell) ;
65+
66+ let testIndexPath = IndexPath ( row: correctedIndex ( visibleIndexPath!. item) , section: 0 ) ;
67+
68+ guard correctedIndexPath != testIndexPath else {
69+ return ; // Do not re-select the same cell
70+ }
71+
72+ // Call supercase to select the correct IndexPath
73+ super. selectItem ( at: correctedIndexPath, animated: animated, scrollPosition: scrollPosition) ;
74+ }
5375}
5476
5577// MARK: - private
You can’t perform that action at this time.
0 commit comments