/ARSwipeToSelectGestureRecognizer

A UIGestureRecognizer subclass to enable Swipe-to-Select/Deselect with a UICollectionView.

Primary LanguageObjective-CMIT LicenseMIT

ARSwipeToSelectGestureRecognizer

animatedgif

Description

This is a UIGestureRecognizer subclass to enable Swipe-to-Select/Deselect with a UICollectionView.

Adding to your project

The easiest way to add ARSwipeToSelectGestureRecognizer to your project is via CocoaPods:

pod 'ARSwipeToSelectGestureRecognizer'

Alternatively you could copy all the files in the Classes/ directory into your project. Be sure 'Copy items to destination group's folder' is checked.

Use

  1. Import the header: #import "ARSwipeToSelectGestureRecognizer.h"
  2. Create an instance of ARSwipeToSelectGestureRecognizer, pass in a block to handle toggling NSIndexPath

####Instantiation, in your UICollectionViewController:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.collectionView.allowsSelection = self.collectionView.allowsMultipleSelection = YES;

    // Do any additional setup after loading the view.
    ARSwipeToSelectGestureRecognizer *gestureRecognizer = [[ARSwipeToSelectGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:) toggleSelectedHandler:^(NSIndexPath *indexPath) {
        if ([[self.collectionView indexPathsForSelectedItems] containsObject:indexPath]) {
            [self.collectionView deselectItemAtIndexPath:indexPath animated:NO];
            [self.collectionView cellForItemAtIndexPath:indexPath].alpha = 1.0;
        } else {
            [self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
            [self.collectionView cellForItemAtIndexPath:indexPath].alpha = 0.5;
        }
    }];
    [self.collectionView addGestureRecognizer:gestureRecognizer];


}

Demo project

  • A demo application that uses ARSwipeToSelectGestureRecognizer to select multiple photos to share with UIActivityViewController can be found in the Demo folder.
  • ARSwipeToSelectPickerController is a UIImagePickerController-like assets picker that utilizes ARMultiSelectGestureRecognizer for swipe-to-select.

Co-Authors

Bitdeli Badge