Giter Site home page Giter Site logo

rakutou / zlswipeableviewswift Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zhxnlai/zlswipeableviewswift

0.0 1.0 0.0 8.9 MB

A simple view for building card like interface like Tinder and Potluck.

License: MIT License

Ruby 1.25% Swift 83.79% Objective-C 7.43% C 1.01% Shell 6.52%

zlswipeableviewswift's Introduction

ZLSwipeableViewSwift

A simple view for building card like interface like Tinder and Potluck. ZLSwipeableViewSwift is based on ZLSwipeableView.

Preview

Custom Animation

direction

Custom Swipe

direction

Custom Direction

direction

Undo

direction

CocoaPods

You can install ZLSwipeableViewSwift through CocoaPods adding the following to your Podfile:

pod 'ZLSwipeableViewSwift'
use_frameworks!

Then import it using:

import ZLSwipeableViewSwift

Usage

Check out the demo app for an example. It contains the following demos: Default, Custom Animation, Custom Swipe, Custom Direction and Undo.

ZLSwipeableView can be added to storyboard or instantiated programmatically:

var swipeableView = ZLSwipeableView(frame: CGRect(x: 0, y: 0, width: 300, height: 500)))
view.addSubview(swipeableView)

The nextView property, a closure that returns an UIView, is used to provide subviews to ZLSwipeableView. After defining it, you can call loadViews and ZLSwipeableView will invoke nextView numPrefetchedViews times and animate the prefetched views.

swipeableView.nextView = {
  return UIView()
}
swipeableView.numPrefetchedViews = 3
swipeableView.loadViews()

The demo app includes examples of both creating views programmatically and loading views from Xib files that use Auto Layout.

To discard all views and reload programmatically:

swipeableView.discardViews()
swipeableView.loadViews()

You can limit the direction swiping happens using the direction property and register callbacks like this. Take a look at the Custom Direction example for details.

swipeableView.direction = .Left | .Up
swipeableView.direction = .All

swipeableView.didStart = {view, location in
    println("Did start swiping view at location: \(location)")
}
swipeableView.swiping = {view, location, translation in
    println("Swiping at view location: \(location) translation: \(translation)")
}
swipeableView.didEnd = {view, location in
    println("Did end swiping view at location: \(location)")
}
swipeableView.didSwipe = {view, direction, vector in
    println("Did swipe view in direction: \(direction), vector: \(vector)")
}
swipeableView.didCancel = {view in
    println("Did cancel swiping view")
}

You can swipe the top view programmatically in one of the predefined directions or with any point and direction in the view's coordinate.

swipeableView.swipeTopView(inDirection: .Left)
swipeableView.swipeTopView(inDirection: .Up)
swipeableView.swipeTopView(inDirection: .Right)
swipeableView.swipeTopView(inDirection: .Down)

swipeableView.swipeTopView(fromPoint: CGPoint(x: 100, y: 30), inDirection: CGVector(dx: 100, dy: -800))

You can also change how the direction gets interpreted by overriding the interpretDirection property. Take a look at the Custom Swipe example for details.

You can create custom animation by overriding the animateView property. Take a look at the Custom Animation example for details.

You can undo/rewind by storing the swiped views and insert them back to the top by calling insertTopView. Take a look at the Undo example for details.

Requirements

  • iOS 7 or higher.

Credits

Big thanks to the contributors of ZLSwipeableView.

License

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

zlswipeableviewswift's People

Contributors

zhxnlai avatar

Watchers

Harimoto avatar

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.