I have a UICollectionView that horizontally scrolls to show one UICollectionViewCell at a time. Each UICollectionViewCell the has a ve
Add tap gesture to your super view
override func viewDidLoad() {
super.viewDidLoad()
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTapView(gesture:)))
view.addGestureRecognizer(tapGesture)
}
@objc func didTapView(gesture: UITapGestureRecognizer) {
view.endEditing(true)
let touchLocation:CGPoint = gesture.location(ofTouch: 0, in: self.collectionView)
let indexPath = self.collectionView.indexPathForItem(at: touchLocation)
if indexPath != nil {
let cell = self.collectionView.cellForItem(at: indexPath!)
if (cell?.isSelected)! {
//PREFORM DESELECT
} else {
//PREFORM SELECT HERE
}
}
}