Friday, September 9, 2016

tap and move collectionView

I was super pumped when found out about "installsStandardGestureForInteractiveMovement"

CollectionView is alway my go to when it comes to UI designs. Coz it makes everything more visualized, and easy to build the connection between the content and the users. 

To practice "installsStandardGestureForInteractiveMovement"
First, set up a basic collection.



import UIKit

private let reuseIdentifier = "Cell"

class PhotoCC: UICollectionViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
    }


    override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return 1
    }


    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 20
    }

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath)
        cell.backgroundColor = UIColor.grayColor()
        return cell
    }
}



Then set self.installsStandardGestureForInteractiveMovement = true
and 
    override func collectionView(collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
//code here

    }

The CollectionView will be ready to go.


The whole project is available at https://github.com/lingzt/CollectionViewTapMovePra

No comments:

Post a Comment