I have a CollectionView
, the cell in CollectionView
has size equal to the screen (CollectionView
has paging enable mode).
I want to press long on the screen, then the CollectionView
will scroll to the next cell.
For example:
I need 1 second to make the CollectionView
scroll to the next cell,
and I press for 2,5 seconds.
The begining time: I am starting long press on the screen and the collection view is now on the first cell.
After the first second: It will scroll to the second cell.
After the second second: It will scroll to the third cell.
The last half second: It still stand on the third cell (because half second is not enough time to make the collection view scroll to the next cell).
I have added the UILongPressGestureRecognizer
to the cell and I have tried like this:
func handleLongPress(longGesture: UILongPressGestureRecognizer) {
if longGesture.state == .Ended {
let p = longGesture.locationInView(self.collectionView)
let indexPath = self.collectionView.indexPathForItemAtPoint(p)
if let indexPath = indexPath {
let row = indexPath.row + 1
let section = indexPath.section
if row < self.photoData.count {
self.collectionView.selectItemAtIndexPath(NSIndexPath(forRow: row, inSection: section), animated: true, scrollPosition: .Right)
}
print(indexPath.row)
} else {
print("Could not find index path")
}
}
}
But I always have to END the long gesture to make the collection view scroll.