All Projects → MaherKSantina → Mspeekcollectionviewdelegateimplementation

MaherKSantina / Mspeekcollectionviewdelegateimplementation

Licence: mit
A custom paging behavior that peeks the previous and next items in a collection view

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Mspeekcollectionviewdelegateimplementation

Multiple-collectionView-in-Multiple-tableView-cells
UICollectionView is embed in UITableViewCell. The collection views are horizontal scrollable. The UITableView can have a section title for each UICollectionView and the number of UICollectionView is equal to the number of sections.
Stars: ✭ 23 (-91.32%)
Mutual labels:  cell, collectionview
Paging Collection View Layout
custom collection view layout that allows you to page by cell, not screen
Stars: ✭ 65 (-75.47%)
Mutual labels:  collectionview, cell
UICollectionViewTutorial
UICollectionView系统学习以及自定义布局。
Stars: ✭ 35 (-86.79%)
Mutual labels:  collectionview
unity-dijkstras-pathfinding
Dijkstra's Pathfinding Algorithm Unity Implementation. (Not being maintained by me, it is just an experiment.)
Stars: ✭ 80 (-69.81%)
Mutual labels:  implementation
ConveRT-pytorch
ConveRT Paper Pytorch Implementation
Stars: ✭ 49 (-81.51%)
Mutual labels:  implementation
SPRCollectionView
iOS:使用CollectionView实现Wallet效果
Stars: ✭ 97 (-63.4%)
Mutual labels:  collectionview
tcscustomrowactionfactory
TCSTableViewRowActionFactory allows you to setup the swipe actions for cells in a table view using UIView and some other convenient methods
Stars: ✭ 24 (-90.94%)
Mutual labels:  cell
ImmediateReflection
.NET library that aims to provide faster usage of C# reflection features. Especially the usage of constructor and members accessors (get/set). It also provides an ObjectWrapper object allowing to use Reflection in a faster way. And finally it offers the possibility to create strongly typed delegates.
Stars: ✭ 30 (-88.68%)
Mutual labels:  delegate
Ethereum Erc721
Non-fungible token implementation for Ethereum-based blockchains.
Stars: ✭ 253 (-4.53%)
Mutual labels:  implementation
preact-delegate
Preact delegate DOM events
Stars: ✭ 17 (-93.58%)
Mutual labels:  delegate
DailyNews
Daily News is a news app with good looking user interface ! Apps architecture is MVVM and used RxSwift for binding.
Stars: ✭ 31 (-88.3%)
Mutual labels:  collectionview
Pageable
An easy way to Pagination or Infinite scrolling for TableView/CollectionView
Stars: ✭ 44 (-83.4%)
Mutual labels:  collectionview
ACBRadialCollectionView
An extension on UICollectionView which automatically transforms collection view cells to a radial path
Stars: ✭ 31 (-88.3%)
Mutual labels:  collectionview
redis
Redis server written in Go / Golang (prototype)
Stars: ✭ 53 (-80%)
Mutual labels:  implementation
promise
A step by step implementation practice of Promise class
Stars: ✭ 31 (-88.3%)
Mutual labels:  implementation
SNAdapter
iOS swift tableview and collectionView Adapter
Stars: ✭ 35 (-86.79%)
Mutual labels:  collectionview
bem-sdk
BEM SDK packages
Stars: ✭ 83 (-68.68%)
Mutual labels:  cell
lips
📘 Lisk improvement proposals
Stars: ✭ 61 (-76.98%)
Mutual labels:  implementation
leetcode
A set of practice note, solution, complexity analysis and test bench to leetcode problem set
Stars: ✭ 31 (-88.3%)
Mutual labels:  implementation
Differencekit
💻 A fast and flexible O(n) difference algorithm framework for Swift collection.
Stars: ✭ 2,986 (+1026.79%)
Mutual labels:  collectionview

MSPeekCollectionViewDelegateImplementation

Version 3.0.0 is here! 🎉

The peeking logic is now done using a custom UICollectionViewLayout which makes it easier to integrate and will introduce less bugs! (And hopefully it will solve all the issues you were facing)

Migrating from 2.0.0 to 3.0.0

I've tried to keep minimal effort to migrate from v2 to v3. Here are the steps:

1- Replace MSPeekCollectionViewDelegateImplementation initialization with MSCollectionViewPeekingBehavior

2- On your collectionView, call configureForPeekingBehavior like this:

collectionView.configureForPeekingBehavior(behavior: behavior)

3- Set the collection view's delegate as the view controller (Or any other class you want)

4- In the collection view delegate function scrollViewWillEndDragging, call the behavior's scrollViewWillEndDragging like this:

func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
        behavior.scrollViewWillEndDragging(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset)
}

5- ???

6- Profit 💰

You can check out the example for a detailed use

Introduction

Build Status

ezgif-2-9f7a86182f

Current design trends require complex designs which allow horizontal scrolling inside vertical scrolling. So to show the users that they can scroll vertically, a peeking item should be shown on the side. This library does exactly that. I wrote this library because there's no pod that does this simple feature. Also, other libraries require me to inherit from a UICollectionViewController, which doesn't give alot of freedom if I'm inheriting from other View Controllers.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • XCode 11.2.1
  • Swift 5

This pod will probably work on older versions of XCode but I haven't tested it.

Installation

MSPeekCollectionViewDelegateImplementation is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'MSPeekCollectionViewDelegateImplementation'

Usage

Storyboard

  1. Drag-Drop a UICollectionView

  2. Set the reuse identifier for the collection view's cell to Cell

  3. Create a reference for the collection view

@IBOutlet weak var collectionView: UICollectionView!
  1. Bind collection view to outlet

  2. Import library

import MSPeekCollectionViewDelegateImplementation
  1. Create a variable of type MSCollectionViewPeekingBehavior
var behavior: MSCollectionViewPeekingBehavior!
  1. In viewDidLoad(), , initialize the behavior and configure the collectionView for peek behavior:
behavior = MSCollectionViewPeekingBehavior()
collectionView.configureForPeekingBehavior(behavior: behavior)

Or you can use whatever arguments from the ones below (Can be combined together as needed):

behavior = MSCollectionViewPeekingBehavior(cellSpacing: 10)
behavior = MSCollectionViewPeekingBehavior(cellPeekWidth: 20)
//minimumItemsToScroll is the minimum number of items that can be scrolled
behavior = MSCollectionViewPeekingBehavior(minimumItemsToScroll: 1)
//maximumItemsToScroll is the maximum number of items that can be scrolled if the scroll distance is large
behavior = MSCollectionViewPeekingBehavior(maximumItemsToScroll: 3)
//numberOfItemsToShow is the number of items that will be shown at the same time.
behavior = MSCollectionViewPeekingBehavior(numberOfItemsToShow: 3)

peek explanation

  1. In viewDidLoad(), set the collection view's delegate to self:
collectionView.delegate = self
  1. In the collection view delegate function scrollViewWillEndDragging, call the behavior's scrollViewWillEndDragging like this:
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
        behavior.scrollViewWillEndDragging(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset)
}
  1. Create the data source implementation as an extension for the ViewController
extension ViewController: UICollectionViewDataSource {
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 4
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath)
        //TODO: Configure cell
        return cell
    }
}
  1. In viewDidLoad(), Set the collection view's data source to self
collectionView.dataSource = self

Working Example

import UIKit
import MSPeekCollectionViewDelegateImplementation

class ViewController: UIViewController {
    
    @IBOutlet weak var collectionView: UICollectionView!
    var behavior = MSCollectionViewPeekingBehavior()

    override func viewDidLoad() {
        super.viewDidLoad()
        collectionView.configureForPeekingBehavior(behavior: behavior)
        collectionView.delegate = self
        collectionView.dataSource = self
    }
}

extension ViewController: UICollectionViewDataSource {
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 4
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath)
        cell.contentView.backgroundColor = UIColor.red
        return cell
    }
}

extension ViewController: UICollectionViewDelegate {
    func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
        behavior.scrollViewWillEndDragging(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset)
    }
    
    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        print(behavior.currentIndex)
    }
}

Features

Scrolling to a specific item

The MSCollectionViewPeekingBehavior now has a function to scroll to a specific index

public func scrollToItem(at index: Int, animated: Bool)

You can do something like:

behavior.scrollToItem(at: 1, animated: true)

Listen to index changes

You can use the scroll view's delegate function to do that (Make sure you conform to UICollectionViewDelegate):

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    print(behavior.currentIndex)
}

Customization

Vertical Scroll Direction

The implementation supports collection views with vertical directions and will automatically position cells correctly, you can set the scrolling and peeking to be vertical using:

delegate = MSCollectionViewPeekingBehavior(scrollDirection: .vertical)
collectionView.configureForPeekingBehavior(behavior: behavior)

Author

Maher Santina, [email protected]

Sponsor

If you're liking this repo I'd really appreciate it if you sponsor me (Orange Juice) so that I can continue supporting this project. I'm also working on adding more reusable UI elements similar to this one to make developer's lives easier. Please see my sponsor page for more details

Contributing

Any contribution is highly appreciated, please see CONTRIBUTING.md for more info.

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].