Giter Site home page Giter Site logo

poi's Introduction

Poi

Pod version Carthage compatible MIT License Swift 4.0.x

You can use tinder UI like tableview method

demo1

Installation

Manual Installation

  1. Use this command
git clone [email protected]:HideakiTouhara/Poi.git
  1. Import Poi.xcodeproj to your project

direct_import1

  1. Add Poi.frameworkiOS to Embedded Binaries

direct_import2

Cocoa Pods

Please write the below code in Podfile

pod ‘Poi’

Carthage

Write this code in your Cartfile.

github "HideakiTouhara/Poi"

and implement this command

carthage update

Add Poi.framework in /Carthage/Build/iOS/ to Embedded Binaries.

carthage_import

Usage

Create PoiView in storyboard or swift file

import Poi

@IBOutlet weak var poiView: PoiView!
// Change View's class to PoiView in Attributes inspector.

or

import Poi

let poiView = PoiView()
self.view.addSubView(poiView)

Conform to PoiViewDataSource and PoiViewDelegate

class ViewController: UIViewController, PoiViewDataSource, PoiViewDelegate {

Designate delegate target.

Please put this code after setting card contents.

poiView.dataSource = self
poiView.delegate = self

PoiViewDataSource method

Set swipeable card number(required method)

func numberOfCards(_ poi: PoiView) -> Int

Set swipeable card(required method)

func poi(_ poi: PoiView, viewForCardAt index: Int) -> UIView

Set overlay image if right or left swiped

func poi(_ poi: PoiView, viewForCardOverlayFor direction: SwipeDirection) -> UIImageView? {
    switch direction {
    case .right:
        return UIImageView(image: #imageLiteral(resourceName: "good"))
    case .left:
        return UIImageView(image: #imageLiteral(resourceName: "bad"))
    }
}

PoiViewDelegate method

When did swipe, this method is called

func poi(_ poi: PoiView, didSwipeCardAt: Int, in direction: SwipeDirection)

When last card was swiped, this method is called

func poi(_ poi: PoiView, runOutOfCardAt: Int, in direction: SwipeDirection)

Public method

Swipe current card

func swipeCurrentCard(to direction: SwipeDirection)

Undo animation and go back previous card

func undo()

Example

Check the Example file!

import UIKit
import Poi

class ViewController: UIViewController, PoiViewDataSource, PoiViewDelegate {

    @IBOutlet weak var poiView: PoiView!

    var sampleCards = [UIView]()

    override func viewDidLoad() {
        super.viewDidLoad()
        var colors = [UIColor.red, UIColor.orange]
        for i in (0..<2) {
            sampleCards.append(UIView(frame: CGRect(x: 0, y: 0, width: 240, height: 128)))
            sampleCards[i].backgroundColor = colors[i]
        }
        poiView.dataSource = self
        poiView.delegate = self
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    // MARK: PoiViewDataSource
    func numberOfCards(_ poi: PoiView) -> Int {
        return 2
    }

    func poi(_ poi: PoiView, viewForCardAt index: Int) -> UIView {
        return sampleCards[index]
    }

    func poi(_ poi: PoiView, viewForCardOverlayFor direction: SwipeDirection) -> UIImageView? {
        switch direction {
        case .right:
            return UIImageView(image: #imageLiteral(resourceName: "good"))
        case .left:
            return UIImageView(image: #imageLiteral(resourceName: "bad"))
        }
    }

    // MARK: PoiViewDelegate
    func poi(_ poi: PoiView, didSwipeCardAt: Int, in direction: SwipeDirection) {
        switch direction {
        case .left:
            print("left")
        case .right:
            print("right")
        }
    }

    func poi(_ poi: PoiView, runOutOfCardAt: Int, in direction: SwipeDirection) {
        print("last")
    }

    // MARK: IBAction
    @IBAction func OKAction(_ sender: UIButton) {
        poiView.swipeCurrentCard(to: .right)
    }

    @IBAction func undo(_ sender: UIButton) {
        poiView.undo()
    }
}

Contribution

Please create issues or submit pull requests for anything.

License

Poi is released under the MIT license.

© 2018 GitHub, Inc.

poi's People

Contributors

hideakitouhara avatar sarbogast avatar keisukeyamashita avatar tflhyl avatar domeniconicoli avatar imac0de avatar nappannda avatar

Stargazers

 avatar Vish avatar A Adisak avatar kazuaki kanno avatar Pin Xan Truong avatar ym avatar  avatar  avatar Oops avatar Hussein Ryalat avatar Okan Kurtuluş avatar Ilya Brin avatar Dean Eigenmann avatar Muhammad Umer avatar Jordan P.R. avatar Rohan Gupta avatar  avatar Leon-Kang avatar Serge Maslyakov avatar Brandon Pimentel avatar Yosuke Nakayama avatar Alex Sherbakov avatar Giovanni Delgado avatar liujun avatar Yuiga Wada avatar Kaho avatar Sergii Kryvoblotskyi avatar Oleksandr Bretsko avatar Kyle Howells avatar  avatar Vijay Kumar avatar Justin avatar Fumiya Tanaka avatar  avatar Daniel Tarazona avatar  avatar Keehun avatar LaoHan avatar Mohammed Abunada avatar Gabriel Rigon avatar Rodrigo Paschoaletto avatar DongHee Kang avatar tomokisun avatar Maike avatar Indrajit Chakrabarty avatar sedat avatar  avatar  avatar Glen de Vries avatar Andrey Yurkevich avatar Paulo Rui Pires Gonçalves avatar Viktor Peschenkov avatar  avatar  avatar umikawa kazuya avatar Nao Oishi avatar  avatar Takanori Hirobe avatar  avatar Kenichi Murao avatar nyagato_00 avatar  avatar  avatar  avatar Carabineiro avatar Morita Naoki avatar

Watchers

Glen de Vries avatar James Cloos avatar Carabineiro avatar

poi's Issues

reloadData() method

Hello,

I have tested your Poi framwork in one of my project and it is very easy to use!

Howewere, I was trouble that there is no reloadData() method in order to be similar to a UITableView or UICollectionView. I think it could be a good feature to add.

Regards.

Swift 4.2 support

Hello !

Since Xcode 10 and Swift 4.2 has been released, the framework doesn't compile anymore.

Regards,

iMac0de

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.