Giter VIP home page Giter VIP logo

rareorderablelayout's Introduction

RAReorderableLayout

A UICollectionView layout which you can move items with drag and drop.

Screen shots

screen shot1 screen shot2

Animation

animated gif

Requirements

  • Swift 3.0 / Xcode 8
    OS X 10.9 or later iOS 8.0 or later watchOS 2.0 or later tvOS 9.0 or later

Still wanna use swift2.2 or 2.3?
-> You can use 0.5.0 instead.

Installation

iOS8 or later

CocoaPods

# Podfile  
use_frameworks!  

target 'YOUR_TARGET_NAME' do
  pod 'RAReorderableLayout'
end

Carthage

 # Cartfile
 github "ra1028/RAReorderableLayout"

Usage

Setup your collection view to use RAReorderableLayout.
You must reorder cells information array in RAReorderableLayoutDelegate protocol to support reordering capability.
Specifically, please refer to Demo-project.

Protocol

Delegate

optional func collectionView(collectionView: UICollectionView, atIndexPath: NSIndexPath, willMoveToIndexPath toIndexPath: NSIndexPath)
optional func collectionView(collectionView: UICollectionView, atIndexPath: NSIndexPath, didMoveToIndexPath toIndexPath: NSIndexPath)

optional func collectionView(collectionView: UICollectionView, allowMoveAtIndexPath indexPath: NSIndexPath) -> Bool
optional func collectionView(collectionView: UICollectionView, atIndexPath: NSIndexPath, canMoveToIndexPath: NSIndexPath) -> Bool

optional func collectionView(collectionView: UICollectionView, collectionViewLayout layout: RAReorderableLayout, willBeginDraggingItemAtIndexPath indexPath: NSIndexPath)
optional func collectionView(collectionView: UICollectionView, collectionViewLayout layout: RAReorderableLayout, didBeginDraggingItemAtIndexPath indexPath: NSIndexPath)
optional func collectionView(collectionView: UICollectionView, collectionViewLayout layout: RAReorderableLayout, willEndDraggingItemToIndexPath indexPath: NSIndexPath)
optional func collectionView(collectionView: UICollectionView, collectionViewLayout layout: RAReorderableLayout, didEndDraggingItemToIndexPath indexPath: NSIndexPath)

Datasource

optional func collectionView(collectionView: UICollectionView, reorderingItemAlphaInSection section: Int) -> CGFloat
optional func scrollTrigerEdgeInsetsInCollectionView(collectionView: UICollectionView) -> UIEdgeInsets
optional func scrollTrigerPaddingInCollectionView(collectionView: UICollectionView) -> UIEdgeInsets
optional func scrollSpeedValueInCollectionView(collectionView: UICollectionView) -> CGFloat

License

RAReorderableLayout is available under the MIT license. See the LICENSE file for more info.

rareorderablelayout's People

Contributors

chrisschneider avatar dimakomar avatar gonghao avatar hirohitokato avatar jamorat avatar jeffreyjackson avatar mergesort avatar pleasantlight avatar ra1028 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rareorderablelayout's Issues

How to use it in Objective-c project?

I follow the tutorial of using swift code in obj-c project, and import "XXXX-Swift.h"
but still get error, the RAReorderableLayout is not recognized in obj-c.

swift3 - Duplicated items problem

If you drag the B and drop left to the A, you'll get two A's. This problem occurs on demo and actual project.

order 1

order 2

// current:
 func collectionView(_ collectionView: UICollectionView, at: IndexPath, didMoveTo toIndexPath: IndexPath) {
        let book = books.remove(at: (toIndexPath as NSIndexPath).item)
        books.insert(book, at: (toIndexPath as NSIndexPath).item)
    }

// fixed: Is this the right solution ?
 func collectionView(_ collectionView: UICollectionView, at: IndexPath, didMoveTo toIndexPath: IndexPath) {
        let book = books.remove(at: (at as NSIndexPath).item)
        books.insert(book, at: (toIndexPath as NSIndexPath).item)
    }

Handle custom Layout

Hi,
I'm trying to use RAReorderableLayout for my swift Project but after many tries I can't get to re-create my custom Layout.

What would be the best way to create something looking like that ?

dashboard

By the way, thank you for your great work ;)

collectionView?.cellForItem is nil and incorrectly unwrapped

I have a collectionView that implements RAReorderableLayout and when I long press a collection item the cells must enter in edit mode and they must look different so that edit buttons appear in each cell view.
Everything works fine unless after I enter the screen, where this collection view is, I long press a cell very quickly and it does not manage to finish redrawing the cells and it reaches this line in your code and crashes because currentCell is nil and you don't unwrap it correctly:

            let currentCell = collectionView?.cellForItem(at: indexPath!)
            
            
            cellFakeView = RACellFakeView(cell: currentCell!)

Please unwrap it correctly so I can still use cocoapods with the bug fix. Thank you!

cellForItemAt or cellForItemAtIndexPath

After migrating to swift 3, cellForItemAtIndexPath needed to change to cellForItemAt, but when I changed it an error appeared saying:

Method 'collectionView(_:cellForItemAt:)' has different argument names from those required by protocol 'RAReorderableLayoutDataSource' ('collectionView(_:cellForItemAtIndexPath:)')

And suggests a quick fix to change it back to cellForItemAtIndexPath.

cannot scroll while dragging down

I have lots of cells out side of the screen, and while dragging, when I drag one cell to the bottom of the screen, the UICollectionView cannot scroll slowly to show more cells.

However, the demo can achieve so. I am not sure what I missed?

I looked at the code, it's related to private func beginScrollIfNeeded()

But I don't know why mine don't trigger the scroll, it goes to

else {
            self.invalidateDisplayLink()
        }

And I have no idea what's the logic while calculating fakeCellTopEdge <= offset + paddingTop + trigerInsetTop and fakeCellEndEdge >= offset + length - paddingEnd - trigerInsetEnd

Screen jumps

When I do my long press, the entire screen "jumps" and then everything works like normal. It's very jarring visually. I only implemented two of your methods so far:

// MARK: - RAReorderableLayoutDataSource
extension HomeScreenViewController: RAReorderableLayoutDataSource {
func collectionView(collectionView: UICollectionView, reorderingItemAlphaInSection section: Int) -> CGFloat {
return 0.3
}
}

// MARK: - RAReorderableLayoutDelegate
extension HomeScreenViewController: RAReorderableLayoutDelegate {
func collectionView(collectionView: UICollectionView, atIndexPath: NSIndexPath, didMoveToIndexPath toIndexPath: NSIndexPath) {
let item = collectionData.removeAtIndex(atIndexPath.item)

    collectionData.insert(item, atIndex: toIndexPath.item)
}

}

Delegate in Swift

Hi, how use your delegate in ObjC library?
I import your library and RAReorderableLayout-Swift.h, but delegate methods not called.

How to use only Pan Gesture ?

When i handle long press , my cell status is change into edit mode . So i don't need handle long press again , i want only handle Pan and move cell because waiting for handle long press is too long to move my cell .
Can anyone help me pls ?

Assist getting started

Hello, is it possible to detect when the rearrange is finished. thus call a function at that point in time?

Make all item fit together

Here is my demo for easy understand

simulator screen shot mar 16 2016 2 27 56 am

I'm beginner with Swift and i don't know this is bug or my mistake, please help me.

Thank you very much.

Support for Rotation

Will you be adding support for rotation or is there a simple way to do that already? The Demo did not support it.

Great Code!

Thanks,

Rob

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.