Giter Site home page Giter Site logo

chengongwen / dragcardcontainer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from liujunliuhong/dragcardcontainer

0.0 0.0 0.0 42.73 MB

A multi-directional card swiping library inspired by Tinder and TanTan

License: MIT License

Ruby 0.76% Objective-C 0.37% Swift 98.87%

dragcardcontainer's Introduction

DragCardContainer

A multi-directional card swiping library inspired by Tinder and TanTan.

Introduction

Due to project reasons, I often need to use the card sliding effect. At the beginning, I also searched for various three-party libraries on GitHub. Fortunately, I found it. But I am not very satisfied, either some of the functions I want are missing, or I feel that the sliding effect of the card is not good, or there are some bugs, and finally I have to modify the source code. After tossing around like this a few times, I decided to write one.

I refer some third-party libraries:

Features

  • Advanced swipe recognition based on velocity and card position.
  • Multiple built-in card stacking styles.
  • Manual and programmatic actions.
  • Smooth card overlay view transitions.
  • Similar to UITableView, dynamic card loading using data source pattern.

Preview

Getting Start

Requirements

  • Deployment target iOS 11.0+
  • Swift 5+
  • Xcode 14+

Installation

CocoaPods

pod 'DragCardContainer'

Or

pod 'DragCardContainer', :git => "https://github.com/liujunliuhong/DragCardContainer.git"

Usage

Setting up the card view

Create your own card container and setting its properties directly.

let cardContainer = DragCardContainer()
// 是否可以无限滑动
cardContainer.infiniteLoop = false
// 数据源
cardContainer.dataSource = self
// 代理
cardContainer.delegate = self
// 可见卡片数量
cardContainer.visibleCount = 3
// 是否可以打印日志
cardContainer.enableLog = true
// 是否禁用卡片拖动
cardContainer.disableTopCardDrag = false
// 是否禁用卡片点击
cardContainer.disableTopCardClick = false

Mode

You can custom mode. Mode is a protocol, ScaleMode implements the Mode protocol.

let mode = ScaleMode()
// 卡片之间间距
mode.cardSpacing = 10
// 方向(可以运行Demo,修改该参数看实际效果)
mode.direction = .bottom
// 最小缩放比例
mode.minimumScale = 0.7
// 卡片最大旋转角度
mode.maximumAngle = 0
// 赋值mode
cardContainer.mode = mode

Configuring the card

Custom Card, inherited from DragCardView.

public final class CardView: DragCardView { }

Configuring the datasource

You must conform the protocol DragCardDataSource.

public func numberOfCards(_ dragCard: DragCardContainer) -> Int {
    return 10
}

public func dragCard(_ dragCard: DragCardContainer, viewForCard index: Int) -> DragCardView {
    let cardView = CardView()
    cardView.allowedDirection = [.left, .right]
    return cardView
}

Configuring the delegate

The protocol DragCardDelegate is optional.

public func dragCard(_ dragCard: DragCardContainer, displayTopCardAt index: Int, with cardView: DragCardView) {
    print("displayTopCardAt: \(index)")
}

public func dragCard(_ dragCard: DragCardContainer, didRemovedTopCardAt index: Int, direction: Direction, with cardView: DragCardView) {
    print("didRemovedTopCardAt: \(index)")
}

public func dragCard(_ dragCard: DragCardContainer, didRemovedLast cardView: DragCardView) {
    print("didRemovedLast")
}

public func dragCard(_ dragCard: DragCardContainer, didSelectTopCardAt index: Int, with cardView: DragCardView) {
    print("didSelectTopCardAt: \(index)")
}

Moving Views

Swiping programmatically

The user can swipe views in the allowed directions. This can also happen programmatically.

cardContainer.swipeTopCard(to: .right)
Rewinding

Returns the most recently swiped card to the top of the card stack.

cardContainer.rewind(from: .right)

Set top level card index

You can set top level card index.

cardContainer.currentTopIndex = 2

Author

liujun, [email protected]

dragcardcontainer's People

Contributors

liujunliuhong avatar qinyuelong 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.