Skip to content

Instantly share code, notes, and snippets.

@Wouter125
Created August 10, 2016 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wouter125/3c0a165cccf623e05a7b02b38be26cf9 to your computer and use it in GitHub Desktop.
Save Wouter125/3c0a165cccf623e05a7b02b38be26cf9 to your computer and use it in GitHub Desktop.
Collectionview Cell detection
func buildCollectionView() {
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.minimumInteritemSpacing = 0;
layout.minimumLineSpacing = 4;
collectionView = UICollectionView(frame: CGRect(x: 0, y: screenSize.midY - 120, width: screenSize.width, height: 180), collectionViewLayout: layout)
collectionView.dataSource = self
collectionView.delegate = self
collectionView.register(VideoCell.self, forCellWithReuseIdentifier: "videoCell")
collectionView.showsHorizontalScrollIndicator = false
collectionView.showsVerticalScrollIndicator = false
collectionView.contentInset = UIEdgeInsetsMake(0, 20, 0, 30)
collectionView.backgroundColor = UIColor.white()
collectionView.alpha = 0.0
collectionView.layer.masksToBounds = false
collectionView.clipsToBounds = false
collectionView.isUserInteractionEnabled = true
//adding gesturerecognizer to the complete view
swipeUpRecognizer = UIPanGestureRecognizer(target: self, action: #selector(self.deleteCell))
swipeUpRecognizer.delegate = self
self.view.addGestureRecognizer(swipeUpRecognizer)
}
func deleteCell(sender: UIPanGestureRecognizer) {
let tapLocation = sender.location(in: self.view)
let indexPath = self.collectionView.indexPathForItem(at: tapLocation)
print(indexPath) //only prints when I'm at 0 - 180. But as you can see from my collectionView it starts at the center of the screen - 120
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment