Coder Social home page Coder Social logo

yudiz-solutions / yzcenterflowlayout Goto Github PK

View Code? Open in Web Editor NEW
37.0 3.0 6.0 8.68 MB

Carousel flow layout for UICollectionView on iOS.

Home Page: https://www.yudiz.com

Swift 100.00%
ios ios-swift carousel flowlayout uicollectionviewlayout layout carousel-view swift-4

yzcenterflowlayout's Introduction

Preview

Demo

Features

  • Animate cell scale while scrolling
  • Rotate cell while scrolling
  • Easy to integrate and use
  • Easy Customizeable

Requirements

  • iOS 11.0 +

Usage

Via code

Create a YZCenterFlowLayout object, set its itemSize and assign it to your UICollectionView.

let layout = YZCenterFlowLayout()
layout.itemSize = CGSizeMake(200, 200)
collectionView.collectionViewLayout = layout

via Interface Builder

Set the UICollectionView layout class to YZCenterFlowLayout, and set its itemSize and its properties as given below

Alt text

Properties

  • animationMode (default is scale with sideItemScale between 0 and 1, default is 0.7, sideItemAlpha: between 0 and 1, default is 0.6, sideItemShift: value in pixels, default is 0)

Can be set only through code.

  • YZCenterFlowLayoutAnimation.scale(sideItemScale: 0.7, sideItemAlpha: 0.6, sideItemShift: 0.0)

The animation apply following 2 here

  1. Scale
  2. Rotation
  • spacingMode (default is fixed spacing of 40 pts) Can be set only through code.
  • YZCenterFlowLayoutSpacingMode.fixed(spacing: CGFloat) Items in the carousel are positioned with a fixed space between them.
  • YZCenterFlowLayoutSpacingMode.overlap(visibleOffset: CGFloat) A fixed part of the side items are visible on the sides of the collection (and therefore the space between items depends on the collection size).

Scale Animation (With cells scale animation while scrolling)

  • Set the animation mode for collectionview flow layout
centerFlowLayout.animationMode = YZCenterFlowLayoutAnimation.scale(sideItemScale: 0.6, sideItemAlpha: 0.6, sideItemShift: 0.0)
  • Set the rotation scale, alpha of collectionView as per your need

Rotation Animation (With cells rotation animation while scrolling)

  • Set the animation mode for collectionview flow layout
centerFlowLayout.animationMode = YZCenterFlowLayoutAnimation.rotation(sideItemAngle: 45, sideItemAlpha: 0.6, sideItemShift: 0)
  • Set the rotation angle, alpha of collectionView as per your need

Detect current indexPath or page while scrolling

  • If you continue to track which current(center) indexPath then use scrollViewDidScroll delegate method. This method called on any offset changes.
func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if let indexPath = centerFlowLayout.currentCenteredIndexPath {
            print("Current IndexPath: \(indexPath)")
        }
        if let page = centerFlowLayout.currentCenteredPage {
            print("Current Page: \(page)")
        }
    }
  • After scrolling end with left or right then you can use the scrollViewDidEndDecelerating delegate method. This method called when scroll view grinds to a halt.
// 
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        if let indexPath = centerFlowLayout.currentCenteredIndexPath {
            print("Current IndexPath: \(indexPath)")
        }
        if let page = centerFlowLayout.currentCenteredPage {
            print("Current Page: \(page)")
        }
    }

Scroll to specifc index

scrollToPage(atIndex index: Int, animated: Bool = true) method use to scroll specific index.

centerFlowLayout.scrollToPage(atIndex: 2, animated: true)

Author

Sandeep Joshi - https://github.com/yudiz-solutions

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.