Giter Site home page Giter Site logo

liujunliuhong / dragcardcontainer Goto Github PK

View Code? Open in Web Editor NEW
89.0 1.0 17.0 42.73 MB

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

License: MIT License

Ruby 0.76% Swift 98.87% Objective-C 0.37%
tantan huapai kapai swift tinder-swiper tinder card cards cardview ios

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

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

Watchers

 avatar

dragcardcontainer's Issues

点击卡片 push 到下一个页面 卡片会自动reload的问题探讨

你好,首先感谢你写的这个库😁。

我在使用中发现了个问题 ,当点击卡片 push 到下一个页面 卡片会自动reload。
看了一下代码是因为YHDragCardContainer.h文件里有下面这个方法:

  • (void)didMoveToWindow{
    [self reloadData:NO];
    }
    这里有个reload操作,导致每次显示和不显示卡片的时候都会reload一下;这就导致当点击的不是第一个卡片进行push的时候或者切换到其他页面的时候,卡片都会reload然后显示第一个卡片。

不明白为何要在这里reload,一般来说应该是使用这个库的时候,使用者来主动reload才好。

当用户快速滑动的时候无法滑动

我看到您在代码设置了userInteractionEnabled为NO,导致了用户每次都等待一会才能滑动,尝试修改却没有改过来 所以放弃了这个库

左滑右滑

大佬我现在想实现一个效果就是左滑下一张 右滑 滑回上一张 该怎么实现呢 求指导

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.