Infinite paging, Smart auto layout, Interface of similar to UIKit.

Overview

LOGO

Carthage compatible Version License Platform

Infinite paging, Smart auto layout, Interface of similar to UIKit.

Appetize's Demo

Demo

Requirements

  • Swift 4.2
  • iOS 8.0 or later

How to Install PagingView

Cocoapods

Add the following to your Podfile:

pod "PagingView"

Carthage

Add the following to your Cartfile:

github "KyoheiG3/PagingView"

Usage

PagingView Variable

weak var dataSource: PagingViewDataSource?
  • DataSource of PagingView. Same as dataSource of UICollectionView.
var pagingMargin: UInt
  • Margin between the content.
  • Default is 0.
var pagingInset: UInt
  • Inset of content relative to size of PagingView.
  • Value of two times than of pagingInset to set for the left and right of contentInset.
  • Default is 0.
var infinite: Bool
  • Infinite looping enabled flag.
  • Default is true.

PagingView Function

func dequeueReusableCellWithReuseIdentifier(identifier: String) -> PagingView.PagingViewCell
  • Used by the delegate to acquire an already allocated cell, in lieu of allocating a new one.
func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)
  • If a nib is registered, it must contain exactly 1 top level object which is a PagingViewCell.
func registerClass<T : PagingView.PagingViewCell>(viewClass: T.Type, forCellWithReuseIdentifier identifier: String)
  • If a class is registered, it will be instantiated via init(frame: CGRect).
func reloadData()
  • Requery the dataSource and delegate as necessary.
func invalidateLayout()
  • Relayout as necessary.
func numberOfSections() -> Int
func numberOfItemsInSection(section: Int) -> Int
  • Information about the current state of the PagingView.
func scrollToPosition(position: PagingView.PagingView.Position, indexPath: IndexPath? = default, animated: Bool = default)
  • To scroll at Position.
  • Cell configure is performed at IndexPath.
func configureAtPosition(position: PagingView.PagingView.Position, toIndexPath: IndexPath? = default)
  • Configure cell of Position.
  • IndexPath of cell in the center if indexPath is nil.

PagingViewDataSource Function

func pagingView(pagingView: PagingView.PagingView, numberOfItemsInSection section: Int) -> Int
  • Paging count number of paging item in section.
func pagingView(pagingView: PagingView.PagingView, cellForItemAtIndexPath indexPath: IndexPath) -> PagingView.PagingViewCell
  • Implementers should always try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithReuseIdentifier:.
optional func numberOfSectionsInPagingView(pagingView: PagingView.PagingView) -> Int
  • Paging count number of paging item section in PagingView.
  • Default return value is 1.
optional func indexPathOfStartingInPagingView(pagingView: PagingView.PagingView) -> IndexPath?
  • IndexPath when pagingView:cellForItemAtIndexPath: is first called
  • Default return value is 0 - 0 of IndexPath instance.

PagingViewDelegate Function

optional func pagingView(pagingView: PagingView.PagingView, willDisplayCell cell: PagingView.PagingViewCell, forItemAtIndexPath indexPath: IndexPath)
optional func pagingView(pagingView: PagingView.PagingView, didEndDisplayingCell cell: PagingView.PagingViewCell, forItemAtIndexPath indexPath: IndexPath)
  • Called at the display and end-display of.

PagingViewCell Function

func prepareForReuse()
  • if the cell is reusable (has a reuse identifier), this is called just before the cell is returned from the paging view method dequeueReusableCellWithReuseIdentifier:.

LICENSE

Under the MIT license. See LICENSE file for details.

Comments
  • Better reloadData()

    Better reloadData()

    Hi. I'm having an issue with reloadData() because it's resetting the scrollview back to the first indexPath. What i'm expecting for reloadData() is the same with tableView/collectionView that it will stay at the current indexPath and just reload the other visible cells. Is this possible? TIA

    opened by rad182 5
  • Duplicate items

    Duplicate items

    So.. What I want is a PagingView with 2 images. Without infinite scrolling.

    I followed your example and made ImagePagingCell extending PagingViewCell (basically just a UIImageView that fills the entire nib like the one in your demo). But the problem is that instead of only having 2 images I have 4, the 2 images duplicated.

    Here's some code:

    // Inside viewDidLoad
    self.pagingView.dataSource = self
    self.pagingView.delegate = self
    self.pagingView.infinite = false
    
    // then...
    func pagingView(pagingView: PagingView, numberOfItemsInSection section: Int) -> Int {
       return 2
    }   
    
    func pagingView(pagingView: PagingView, cellForItemAtIndexPath indexPath: NSIndexPath) -> PagingViewCell {
           pageControl.currentPage = indexPath.row
           let cell = pagingView.dequeueReusableCellWithReuseIdentifier("ImagePagingViewCell")
           var url : String = ""
           if indexPath.row == 0 {
              url = (self.data?.img0)!
           } else if indexPath.row == 1 {
               url = (self.data?.img1)!
           }
           let imageURL = NSURL(string: "\(Const.URL_BASE_IMAGE)\(url)")
           if let cell = cell as? ImagePageViewCell {
               cell.imageView.af_setImageWithURL(imageURL!)
           }
           return cell
    }
    
    

    Any ideas why I'm getting 4 pages instead of 2?

    Thanks

    bug 
    opened by fnk0 5
  • Fix issue #14 There is the error in displaying pages

    Fix issue #14 There is the error in displaying pages

    After I adjusted the code... Test Case infinite == false && itemToShow.count == 2 infinite == true && itemToShow.count == 2 infinite == false && itemToShow.count >2 infinite == true && itemToShow.count > 2 Result Every cases works fine. Thanks

    opened by yangjehpark 4
  • force layout right away

    force layout right away

    the thing is when I call reloadData and tries to get the visiblecells it's empty because layoutSubviews hasn't be called yet. so with this it will force layoutSubviews right away. Let me know if this is okay.

    opened by rad182 3
  • Infinite Loop with one or two images.

    Infinite Loop with one or two images.

    When you have only one or two images and the infinite loop is set to true, it's showing only one image and bug when you swipe right. (with more than 2 images work fine)

    opened by diegoalex 2
  • added defer for checking if indexPath is out of bounds

    added defer for checking if indexPath is out of bounds

    Don't stop if the indexPath doesn't exist or out of bound. My use case for this if I want to clear out the scrollView I return 0 to numberOfItems in dataSource and tries to reloadData(). It should just clear out the scrollview

    Let me know if you have any good solution for this.

    opened by rad182 2
  • Error displaying the second item

    Error displaying the second item

    self.pageView.delegate = self
    self.pageView.dataSource = self
    self.pageView.infinite = false
    
    func numberOfSectionsInPagingView(pagingView: PagingView) -> Int {
        return 1
    }
    

    Total 2 item

    func pagingView(pagingView: PagingView, numberOfItemsInSection section: Int) -> Int {
        return 2
    }
    

    Displaying the second item

    func indexPathOfStartingInPagingView(pagingView: PagingView) -> NSIndexPath? {
        return NSIndexPath(forRow: 1, inSection: 0)
    }
    
    opened by Rezanov-Onliner 1
  • Disable infinite looping issue

    Disable infinite looping issue

    Hi

    When I set infinite looping flag to false.

    Now scroll the page to 1/2/3... from 0 manually, assume the index comes to 2. Then use the api pagingView.scrollToPosition(.center, indexPath: IndexPath(item: 0, section: 0), animated: false)

    Ok, now the index is 0, but this time infinite scrolling is turned on again. I can scroll to 4 directly, just like the infinite looping flat fails.

    Here is the code

    
    class DemoViewController: UIViewController {
        @IBOutlet weak var pagingView: PagingView!
            
        var colors: [UIColor] = ["0", "1", "2", "3", "4", "5"].map({ _ in UIColor.randomColor })
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            pagingView.dataSource = self
            pagingView.delegate = self
            pagingView.pagingMargin = 0
            pagingView.pagingInset = 0
            pagingView.infinite = false
            pagingView.showsHorizontalScrollIndicator = false
            
            let nib = UINib(nibName: "DemoViewCell", bundle: nil)
            pagingView.registerNib(nib, forCellWithReuseIdentifier: "DemoViewCell")
            
        }
        
        @IBAction func scrollManually(_ sender: Any) {
            pagingView.scrollToPosition(.center, indexPath: IndexPath(item: 0, section: 0), animated: false)
        }
        
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
        
    }
    
    extension DemoViewController: PagingViewDataSource, PagingViewDelegate {
        func scrollViewDidScroll(_ scrollView: UIScrollView) {
            if let centerCell = pagingView.visibleCenterCell() {
                title = "\(centerCell.indexPath.item)"
            }
        }
        
        func pagingView(_ pagingView: PagingView, numberOfItemsInSection section: Int) -> Int {
            return colors.count
        }
        
        func pagingView(_ pagingView: PagingView, cellForItemAtIndexPath indexPath: IndexPath) -> PagingViewCell {
            let cell = pagingView.dequeueReusableCellWithReuseIdentifier("DemoViewCell")
            if let cell = cell as? DemoViewCell {
                let color = colors[indexPath.item]
                cell.backgroundColor = color
                cell.label.text = "\(indexPath.item)"
            }
            return cell
        }
    }
    

    Here is the demo video: https://user-images.githubusercontent.com/16531533/170958760-dee49e3e-9e80-4b70-a840-4aebf9c72849.mov

    opened by jackdebugging 1
  • Crash PagingView.swift line 388

    Crash PagingView.swift line 388

    Version PagingView (0.5.1) SIGTRAP 0x00000000019d4b84

    Crashed: com.apple.main-thread
    0  libswiftCore.dylib             0x19d4b84 globalinit_33_FD9A49A256BEB6AF7C48013347ADC3BA_func6 + 100612
    1  PagingView                     0x14467f8 PagingView.reloadContentView() (PagingView.swift:388)
    2  PagingView                     0x1447288 PagingView.layoutSubviews() (PagingView.swift:439)
    3  PagingView                     0x1447634 @objc PagingView.layoutSubviews() (PagingView.swift)
    4  UIKit                          0x2102f483 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1224
    5  QuartzCore                     0x1ec87cb7 -[CALayer layoutSublayers] + 126
    6  QuartzCore                     0x1ec7bd77 CA::Layer::layout_if_needed(CA::Transaction*) + 354
    7  UIKit                          0x210431a7 -[UIView(Hierarchy) layoutBelowIfNeeded] + 1176
    8  MyApp              0x1cdde4 specialized APagingBaseCell.setData(_:page:) (APagingBaseCell.swift:81)
    9  MyApp              0x3719bc specialized AListView.collectionView(_:cellForItemAt:) (AListView.swift:154)
    10 MyApp              0x3705a0 @objc AListView.collectionView(_:cellForItemAt:) (AListView.swift)
    11 UIKit                          0x218b3851 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 420
    12 UIKit                          0x210935e1 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 42
    13 UIKit                          0x210917f7 -[UICollectionView _updateVisibleCellsNow:] + 4076
    14 UIKit                          0x2108c3d7 -[UICollectionView layoutSubviews] + 398
    15 UIKit                          0x2102f483 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1224
    16 QuartzCore                     0x1ec87cb7 -[CALayer layoutSublayers] + 126
    17 QuartzCore                     0x1ec7bd77 CA::Layer::layout_if_needed(CA::Transaction*) + 354
    18 QuartzCore                     0x1ec7bc05 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
    19 QuartzCore                     0x1ec0a839 CA::Context::commit_transaction(CA::Transaction*) + 320
    20 QuartzCore                     0x1ec28fdb CA::Transaction::commit() + 578
    21 QuartzCore                     0x1ec29b2f CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 162
    22 CoreFoundation                 0x1bdbb803 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
    23 CoreFoundation                 0x1bdb9a55 __CFRunLoopDoObservers + 282
    24 CoreFoundation                 0x1bdba017 __CFRunLoopRun + 1358
    25 CoreFoundation                 0x1bd0d1af CFRunLoopRunSpecific + 470
    26 CoreFoundation                 0x1bd0cfd1 CFRunLoopRunInMode + 104
    27 GraphicsServices               0x1d4b7b41 GSEventRunModal + 80
    28 UIKit                          0x21095a53 UIApplicationMain + 150
    29 MyApp              0x110ae4 main (A.swift:44)
    30 libdyld.dylib                  0x1b4fa4eb start + 2
    

    @KyoheiG3

    opened by Ewg777 3
  • There is a bug with the center page

    There is a bug with the center page

    when having a UIRefreshControl assigned to the PagingView, this refreshControl appears on one of the pages next the the center page. So my guess that the wrong page is centered...

    opened by TvdBrink 0
  • There is the error in displaying pages

    There is the error in displaying pages

    Using this values of parameters

    pagingView.pagingMargin = 0
    pagingView.pagingInset = 0
    pagingView.infinite = false
    

    the first three pages are displayed only.

    Steps to reproduce:

    1. Open "PagingViewExample" project
    2. Set the above values of parameters in the "DemoViewControler" class
    3. Run project
    4. Open "Demo" tab
    opened by Rezanov-Onliner 0
Releases(0.4.0)
  • 0.4.0(Oct 15, 2015)

    Not stored IndexPath.

    IndexPath will not be stored in reload. Please use the following if necessary.

    optional func indexPathOfStartingInPagingView(pagingView: PagingView.PagingView) -> NSIndexPath?
    
    Source code(tar.gz)
    Source code(zip)
Owner
Kyohei Ito
Kyohei Ito
Conv smart represent UICollectionView data structure more than UIKit.

Conv Conv smart represent UICollectionView data structure more than UIKit. Easy definition for UICollectionView DataSource and Delegate methods. And C

bannzai 155 May 12, 2022
A custom paging behavior that peeks the previous and next items in a collection view

MSPeekCollectionViewDelegateImplementation Version 3.0.0 is here! ?? The peeking logic is now done using a custom UICollectionViewLayout which makes i

Maher Santina 353 Dec 16, 2022
Custom CollectionViewLayout class for CollectionView paging mode to work properly

PagingCollectionViewLayout About How to use About ⚠️ Custom class, which is inherited from UICollectionViewFlowLayout, developed for properly work Col

Vladislav 2 Jan 17, 2022
PJFDataSource is a small library that provides a simple, clean architecture for your app to manage its data sources while providing a consistent user interface for common content states (i.e. loading, loaded, empty, and error).

PJFDataSource PJFDataSource is a small library that provides a simple, clean architecture for your app to manage its data sources while providing a co

Square 88 Jun 30, 2022
UICollectionView layout for presenting of the overlapping cells.

StickyCollectionView UICollectionView layout for presenting of the overlapping cells. Objective-C version here Checkout demo Overview Installation Man

Bogdan Matveev 325 Oct 11, 2022
Infinite paging controller, scrolling through contents and title bar scrolls with a delay

PageController PageController is infinite paging controller, scrolling through contents and title bar scrolls with a delay. Then it provide user inter

Hirohisa Kawasaki 408 Nov 28, 2022
Infinite paging controller, scrolling through contents and title bar scrolls with a delay

PageController PageController is infinite paging controller, scrolling through contents and title bar scrolls with a delay. Then it provide user inter

Hirohisa Kawasaki 408 Nov 28, 2022
A custom layout built on top of SwiftUI's Layout API that lays elements out in multiple lines. Similar to flex-wrap in CSS, CollectionViewFlowLayout.

WrapLayout A custom layout built on top of SwiftUI's Layout API that lays elements out in multiple lines. Similar to flex-wrap in CSS, CollectionViewF

Hiroshi Kimura 6 Sep 27, 2022
Auto Layout (and manual layout) in one line.

Auto Layout (and manual layout) in one line. Quick Look view.bb.centerX().below(view2).size(100) It’s equivalent to iOS 9 API: view.centerXAnchor.cons

Javier Zhang 74 Oct 19, 2022
Auto Layout made easy with the Custom Layout.

Auto Layout made easy with the Custom Layout. Getting started CocoaPods CocoaPods is a dependency manager for Cocoa projects. You can install it with

Malith Nadeeshan 1 Jan 16, 2022
Conv smart represent UICollectionView data structure more than UIKit.

Conv Conv smart represent UICollectionView data structure more than UIKit. Easy definition for UICollectionView DataSource and Delegate methods. And C

bannzai 157 Nov 25, 2022
Conv smart represent UICollectionView data structure more than UIKit.

Conv Conv smart represent UICollectionView data structure more than UIKit. Easy definition for UICollectionView DataSource and Delegate methods. And C

bannzai 155 May 12, 2022
Async+ for Swift provides a simple chainable interface for your async and throwing code, similar to promises and futures

Async+ for Swift provides a simple chainable interface for your async and throwing code, similar to promises and futures. Have the best of both worlds

async_plus 132 Jan 6, 2023
A peer to peer framework for OS X, iOS and watchOS 2 that presents a similar interface to the MultipeerConnectivity framework

This repository is a peer to peer framework for OS X, iOS and watchOS 2 that presents a similar interface to the MultipeerConnectivity framework (which is iOS only) that lets you connect any 2 devices from any platform. This framework works with peer to peer networks like bluetooth and ad hoc wifi networks when available it also falls back onto using a wifi router when necessary. It is built on top of CFNetwork and NSNetService. It uses the newest Swift 2's features like error handling and protocol extensions.

Manav Gabhawala 93 Aug 2, 2022
Give pull-to-refresh & infinite scrolling to any UIScrollView with 1 line of code.

SVPullToRefresh + SVInfiniteScrolling These UIScrollView categories makes it super easy to add pull-to-refresh and infinite scrolling fonctionalities

Sam Vermette 4.9k Dec 1, 2022
ESPullToRefresh is an easy-to-use component that give pull-to-refresh and infinite-scrolling implemention for developers.

ESPullToRefresh is an easy-to-use component that give pull-to-refresh and infinite-scrolling implemention for developers.

Vincent Li 1.7k Jan 8, 2023
Flix is an app the uses the the movies database to get upcoming movies, with infinite scrolling

Flix Flix is an app the uses the the movies database to get upcoming movies, with infinite scrolling Libraries Flix uses Swift Package Manager (SPM),

null 0 Oct 31, 2021
This is a control that helps you dramatically ease your infinite scroll processing.

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

Minseok Kang 0 Nov 15, 2021
iOS 7+ Calendar (Date Picker) with Infinite Scrolling.

RSDayFlow iOS 7 Calendar with Infinite Scrolling. Only need 4 lines of code to set up. RSDayFlow is a slim fork of DayFlow with updates and extensions

Ruslan Skorb 844 Sep 14, 2022