Git Product home page Git Product logo

ltinfinitescrollview-swift's Introduction

LTInfiniteScrollViewSwift

Demo

1. You can apply animation to each view during the scroll:

LTInfiniteScrollView

2. The iOS 9 task switcher animation can be implemented in ten minutes with the support of this lib:

LTInfiniteScrollView

3. The fancy menu can also be implemented easily:

LTInfiniteScrollView

You can find the full demo in the Objective-C version: https://github.com/ltebean/LTInfiniteScrollView.

Installation

pod 'LTInfiniteScrollViewSwift'

Or just copy LTInfiniteScrollView.swift into your project.

Usage

You can create the scroll view by:

scrollView = LTInfiniteScrollView(frame: CGRect(x: 0, y: 200, width: screenWidth, height: 300))
scrollView.dataSource = self
scrollView.delegate = self
scrollView.maxScrollDistance = 5
scrollView.reloadData(initialIndex: 0)

Then implement LTInfiniteScrollViewDataSource protocol:

public protocol LTInfiniteScrollViewDataSource: class {
    func viewAtIndex(index: Int, reusingView view: UIView?) -> UIView
    func numberOfViews() -> Int
    func numberOfVisibleViews() -> Int
}

Sample code:

func numberOfViews() -> Int {
    return 100
}
    
func numberOfVisibleViews() -> Int {
    return 5
}

func viewAtIndex(index: Int, reusingView view: UIView?) -> UIView {
    if let label = view as? UILabel {
        label.text = "\(index)"
        return label
    }
    else {
        let size = screenWidth / CGFloat(numberOfVisibleViews())
        let label = UILabel(frame: CGRect(x: 0, y: 0, width: size, height: size))
        label.textAlignment = .Center
        label.backgroundColor = UIColor.darkGrayColor()
        label.textColor = UIColor.whiteColor()
        label.layer.cornerRadius = size / 2
        label.layer.masksToBounds = true
        label.text = "\(index)"
        return label
    }
}

If you want to apply any animation during scrolling, implement LTInfiniteScrollViewDelegate protocol:

public protocol LTInfiniteScrollViewDelegate: class {
    func updateView(view: UIView, withProgress progress: CGFloat, scrollDirection direction: ScrollDirection)
}

The value of progress dependends on the position of that view, if there are 5 visible views, the value will be ranged from -2 to 2:

|                  |
|-2  -1   0   1   2|
|                  |

You can clone the project and investigate the example for details.

ltinfinitescrollview-swift's People

Contributors

ltebean avatar robindaugherty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ltinfinitescrollview-swift's Issues

"iOS 9 task switcher animation"

Hi,

Very cool framework!
Do you mind adding the "iOS 9 task switcher animation" gif source to the demo project?

Thanks,
Leo

how to choose 0, 1 indexes?

Hi, Leo! Not an issue, but actually is request, - if it possible somehow to be chosen 0, 1 indexes in scrollViewDidScrollToIndex ? The leftmost view starts 2 and so on... Thanks!

Crash when using show(push) viewcontroller

Hi sir,
I'm using your pod. But I have the problem that my app crash when I press a button to show the viewController that contain the UIView with LTInfiniteScrollView as its subclass.

If I set the viewController with LTInfiniteScrollView , the crash won't happen. As I tried to see the problem, I recognized that when I push/show the viewController.

private func setup() {

    scrollView = UIScrollView(frame: CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)))
    scrollView.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
    scrollView.showsHorizontalScrollIndicator = false
    scrollView.delegate = self
    scrollView.clipsToBounds = false
    self.addSubview(scrollView)
}

this setup is not work.
I tried to put this code in to this ,it wasn't crash. but the scrollview is laid behind the uiviewController now.

let rv = UIApplication.sharedApplication().keyWindow!.subviews.last! as UIView
rv.addSubview(self.scrollView)

Can you help me to fix this problem? I'm a Swift beginner so please help me, I really need your pod to fix my problem.

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.