3

I have used this DoImagePickerController but it did not work for me.
It selects/ unselects a particular item on an index.

See below image from DoImagePickerController

enter image description here

I need to select/unselect all the items from pick index to current index using the UIPanGestureRecognizer.

I need to like below image sample.

enter image description here

enter image description here

if have you any sample app/demo for this please help me.

vipinsaini0
  • 541
  • 1
  • 7
  • 26

1 Answers1

1

Trace the indexpath of selection using gesture's location and loop until the selected indexpath

    func makeSelection(on indexPath : IndexPath){
    let cell = collectionView(collectionView, cellForItemAt: indexPath) as! GalleryPhotoCell
    
    if selectionMode {
        //gesture used for selecting photos
        print("On selection")

        cell.tapSelection ? nil : collectionView(collectionView, didSelectItemAt: indexPath)
    }
    else {
        //gesture used for unselecting photos
        print("On unselection")

        cell.tapSelection ? collectionView(collectionView, didSelectItemAt: indexPath) : nil
    }
}

func makeSelection(upto count : Int){
    guard let start = prevIndex else {return}

    if count > 0 {
        
        for item in 0 ..< count {
            let index = IndexPath(item: start.item + item + 1, section: start.section)
            makeSelection(on: index)

        }
    }
    else {
        for item in 0 ..< abs(count){
            let index = IndexPath(item: start.item - item - 1, section: start.section)
            makeSelection(on: index)
        }
    }
}
Lakshmi C
  • 31
  • 8