Exact, the slider is hidden and is not in general manipulated directly.
So, I tried along this way (but did not fully test):
- in IB, add a swipeGestureRecogniqer to collection
- in the viewController where the collectionView is, add:
@IBAction func swipeDetected(_ sender: UISwipeGestureRecognizer) {
print("Swipe detected")
// here compute the first visible row, taht will let you compute the %
}
It does work like this.
But I had to add the gesture programmatically :
class Item1ViewController: UIViewController,UICollectionViewDataSource,UICollectionViewDelegate, UIGestureRecognizerDelegate {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
let swipeGestureUp = UISwipeGestureRecognizer(target: self, action: #selector(swipeDetected))
swipeGestureUp.numberOfTouchesRequired = 1
swipeGestureUp.direction = .up
swipeGestureUp.delegate = self
collectionView.addGestureRecognizer(swipeGestureUp)
let swipeGestureDown = UISwipeGestureRecognizer(target: self, action: #selector(swipeDetected))
swipeGestureDown.numberOfTouchesRequired = 1
swipeGestureDown.direction = .down
swipeGestureDown.delegate = self
collectionView.addGestureRecognizer(swipeGestureDown)
let swipeGestureLeft = UISwipeGestureRecognizer(target: self, action: #selector(swipeDetected))
swipeGestureLeft.numberOfTouchesRequired = 1
swipeGestureLeft.direction = .left
swipeGestureLeft.delegate = self
collectionView.addGestureRecognizer(swipeGestureLeft)
let swipeGestureRight = UISwipeGestureRecognizer(target: self, action: #selector(swipeDetected))
swipeGestureRight.numberOfTouchesRequired = 1
swipeGestureRight.direction = .right
swipeGestureRight.delegate = self
collectionView.addGestureRecognizer(swipeGestureRight)
collectionView.isScrollEnabled = false // Needed for vertical swipe to be detected ; but clearly, not good !
}
The problem in my test app is that I have to desable collection view scrolling for vertical swipe to be detected !
So you should evaluate the swipe, or decide to move by one row for each swipe, and scroll to the new row (may be select it) in the swipeDetected func.
@objc func swipeDetected(sender: UISwipeGestureRecognizer) {
print("Swipe detected", sender.direction)
// Here, for up and down, scroll by 1 row and redraw accordingly
}