Latest 0.0.2
Homepage https://github.com/Mycose/CMLazyScrollViewController
License MIT
Platforms ios 8.0
Dependencies CMPageControl
Authors

Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.
or
https://appetize.io/app/qcb2rwc82uu53thuy2efvez6hr?device=iphone5s&scale=75&orientation=portrait&osVersion=9.3

Future

  • Smoothen the animation when you end dragging on infinite mode without pagging
  • Any ideas or request ?

Algorithm

For the infinite carousel/scroll etc… I see only two possibilities:
1- Use a UICollectionView or UITableView, setting the number of elements to a really high value, and scroll at the middle at the beginning, and then play with / and % to have the right index everytime
2- Imagine you have a UIScrollView with pages like this 1 2 3 4 5. Basically you just want to have 5 1 2 3 4 5 1, and when the user scroll and arrive on the first 1 or the second 5, you want to scroll back at the beginning or the end without animation and seemlessly, it create the feeling of infinity since you will basically scroll over and over on the same elements

In this projet I used the second way

CMLazyScrollViewController

CMLazyScrollViewController is a UIViewController which has a UIScrollView and UIPageControl.
The delegation of the CMLazyScrollViewController ask for UIViewController to put in the scroll view on a page system
There is a lazy option (only 3 per 3 view controllers in the memory) and infinite mode.

CMLazyScrollViewController Properties:

// properties for the scrollview
public var isPagingEnable = true
public var isHorizontalScrollIndicatorHidden = false
public var isVerticalScrollIndicatorHidden = false
// scroll view delegate which will be call after every delegate function
public var scrollDelegate : UIScrollViewDelegate?

CMLazyScrollViewController Usage Example:

let carousel = CMLazyScrollViewController()
carousel.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
carousel.infinite = true
carousel.isPagingEnable = true
carousel.delegate = self
self.addChildViewController(carousel)
self.view.addSubview(carousel.view)

CMLazyScrollViewController Delegation : CMLazyScrollViewControllerDelegate

// ask for the number of view in the controller
func numberOfViewControllersIn(scrollViewController : CMLazyScrollViewController) -> Int
// request a view controller to show at the index
func viewControllerIn(scrollViewController : CMLazyScrollViewController, atIndex: Int) -> UIViewController    

Installation

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

pod 'CMLazyScrollViewController'

Author

Mycose, [email protected]

License

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

Latest podspec

{
    "name": "CMLazyScrollViewController",
    "version": "0.0.2",
    "summary": "Lazy ScrollView with support for infinite scroll (using a paging system with UIViewControllers and not UIViews)",
    "description": "CMLazyScrollViewController is a controller that I developped in first place to have an infinite carousel of images easily and that i don't have to redo it everytime. And I thought that it would be better than a basic carousel to have UIViewControllers instead of UIViews, to have more complex page. Also I choose to inherit from a UIViewController instead of a UIView because I wanted to be able to add childViewControllers",
    "homepage": "https://github.com/Mycose/CMLazyScrollViewController",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Cleu0301ment Morissard": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Mycose/CMLazyScrollViewController.git",
        "tag": "0.0.2"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "CMLazyScrollViewController/Classes/**/*",
    "dependencies": {
        "CMPageControl": [
            "~> 0.0.3"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This