Poi 3.1.0

Poi 3.1.0

Hideaki Touhara 维护。



Poi 3.1.0

  • 作者
  • HideakiTouhara

Poi

Pod version Carthage compatible MIT License Swift 4.0.x

您可以使用类似 tableview 的方法来使用 tinder UI

demo

安装

手动安装

  1. 您使用此命令:
git clone [email protected]:HideakiTouhara/Poi.git
  1. 将 Poi.xcodeproj 导入到您的项目中

direct_import1

  1. 将 Poi.frameworkiOS 添加到嵌入式二进制文件中

direct_import2

Cocoa Pods

请在 Podfile 中写入以下代码

pod ‘Poi’

Carthage

在 Cartfile 中写入这段代码。

github "HideakiTouhara/Poi"

并执行以下命令:

carthage update

将 Poi.framework 添加到 /Carthage/Build/iOS/,并加入到嵌入式二进制文件中。

carthage_import

使用方法

在Storyboard或Swift文件中创建PoiView

import Poi

@IBOutlet weak var PoiView: PoiView!
// You should change poiView's class to PoiView in Attributes inspector.

或者

import Poi

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

遵守PoiViewDataSource和PoiViewDelegate协议

class ViewController: UIViewController, PoiViewDataSource, PoiViewDelegate {

指定代理目标。

请在此代码设置卡片内容之后放置。

poiView.dataSource = self
poiView.delegate = self

PoiViewDataSource方法

设置可滑动的卡片数量(必需方法)

func numberOfCards(_ poi: PoiView) -> Int

设置可滑动的卡片(必需方法)

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

设置左右滑动时显示的叠加图像

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方法

滑动时调用此方法

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

最后一张卡片滑动时调用此方法

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

公共方法

滑动当前卡片

func swipeCurrentCard(to direction: SwipeDirection)

撤销动画并返回上一张卡片

func undo()

示例

查看示例文件!

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()
    }
}

贡献

请为任何内容创建问题或提交拉取请求。

许可证

Poi遵循MIT许可证发布。

© 2018 GitHub, Inc.