Last active
April 14, 2019 00:25
-
-
Save JeremyXue77/68882c0bae57484a22b6675f5a93a20f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| protocol GestureCollectionViewDelegate: class { | |
| func move(point: CGPoint) | |
| func selectedItem(indexPath: IndexPath) | |
| func cancel() | |
| } | |
| class GestureCollectionView: UICollectionView { | |
| weak var gestureDelegate: GestureCollectionViewDelegate? | |
| open override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { | |
| if let point = touches.first?.location(in: self) { | |
| if let indexPath = self.indexPathForItem(at: point) { | |
| gestureDelegate?.selectedItem(indexPath: indexPath) | |
| } else { | |
| gestureDelegate?.move(point: point) | |
| } | |
| } | |
| } | |
| override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { | |
| gestureDelegate?.cancel() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment