Giter Site home page Giter Site logo

hpique / lxreorderablecollectionviewflowlayout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lxcid/lxreorderablecollectionviewflowlayout

0.0 2.0 0.0 218 KB

Extends `UICollectionViewFlowLayout` to support reordering of cells. Similar to long press and pan on books in iBook.

lxreorderablecollectionviewflowlayout's Introduction

LXReorderableCollectionViewFlowLayout

Extends UICollectionViewFlowLayout to support reordering of cells. Similar to long press and pan on books in iBook.

Features

The goal of LXReorderableCollectionViewFlowLayout is to provides capability for reordering of cell, similar to iBook.

  • Long press on cell invoke reordering capability.
  • When reordering capability is invoked, fade the selected cell from highlighted to normal state.
  • Drag around the selected cell to move it to the desired location, other cells adjust accordingly. Callback in the form of delegate methods are invoked.
  • Drag selected cell to the edges, depending on scroll direction, autoscroll in the desired direction.
  • Release to stop reordering.

Getting Started

Screenshot

  1. Drag the LXReorderableCollectionViewFlowLayout folder into your project.

  2. Initialize/Setup your collection view to use LXReorderableCollectionViewFlowLayout.

  3. If you setup your collection view programmatically, make sure you call [LXReorderableCollectionViewFlowLayout setUpGestureRecognizersOnCollectionView] instance method after the collection view is setup.

    [theReorderableCollectionViewFlowLayout setUpGestureRecognizersOnCollectionView];
    
  4. The collection view controller that is to support reordering capability must conforms to LXReorderableCollectionViewDelegateFlowLayout protocol. For example,

    - (void)collectionView:(UICollectionView *)theCollectionView layout:(UICollectionViewLayout *)theLayout itemAtIndexPath:(NSIndexPath *)theFromIndexPath willMoveToIndexPath:(NSIndexPath *)theToIndexPath {
        id theFromItem = [self.deck objectAtIndex:theFromIndexPath.item];
        [self.deck removeObjectAtIndex:theFromIndexPath.item];
        [self.deck insertObject:theFromItem atIndex:theToIndexPath.item];
    }
    
  5. Setup your collection view accordingly to your need, run and see it in action! :D

Limitations

Collection view come with a default long press gesture recognizer and because we defined our own custom long press gesture recognizer, we created a link between them that requires the custom one to fails before the default one can began.

In short, we took over the responsibility of long press gesture with the custom one from the default one. You can disable the custom long press gesture recognizer with the following code snippet, self.longPressGestureRecognizer.enabled = YES, which enabled the default behavior again.

Requirements

  • ARC
  • iOS 6
  • Xcode 4.5 and above

Credits

LXReorderableCollectionViewFlowLayout is created by Stan Chang Khin Boon as part of a project under buUuk.

Many thanks to MaximilianL in the Apple Developer Forums for sharing his implementation which lead me to this project.

The playing cards in the demo are downloaded from http://www.jfitz.com/cards/.

README.md structure is heavily referenced from AFNetworking.

Creators

Stan Chang Khin Boon
@lxcid

License

LXReorderableCollectionViewFlowLayout is available under the MIT license.

lxreorderablecollectionviewflowlayout's People

Contributors

lxcid avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.