Skip to content

matthewpalmer/koloda

Repository files navigation

KolodaView

Yalantis

Check this article on our blog

Preview

Purpose

KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS. It adds convenient functionality such as a UITableView-style dataSource/delegate interface for loading views dynamically, and efficient view loading, unloading .

Supported OS & SDK Versions

  • Supported build target - iOS 8.0 (Xcode 6.2)

ARC Compatibility

KolodaView requires ARC.

Thread Safety

KolodaView is subclassed from UIView and - as with all UIKit components - it should only be accessed from the main thread. You may wish to use threads for loading or updating KolodaView contents or items, but always ensure that once your content has loaded, you switch back to the main thread before updating the KolodaView.

Installation

To install via CocoaPods add this line to your Podfile

use_frameworks!
pod "Koloda"

To install manually the KolodaView class in an app, just drag the KolodaView, DraggableCardView, OverlayView class files (demo files and assets are not needed) into your project. Also you need to install facebook-pop. Or add bridging header if you are using CocoaPods.

Properties

The KolodaView has the following properties:

	weak var dataSource: KolodaViewDataSource!

An object that supports the KolodaViewDataSource protocol and can provide views to populate the KolodaView.

	weak var delegate: KolodaViewDelegate?

An object that supports the KolodaViewDelegate protocol and can respond to KolodaView events.

    public var currentCardNumber

The index of front card in the KolodaView (read only).

    public var countOfCards

The count of cards in the KolodaView (read only). To set this, implement the kolodaNumberOfCards: dataSource method.

    var countOfVisibleCards

The count of displayed cards in the KolodaView.

Methods

The KolodaView class has the following methods:

	func reloadData()

This reloads all KolodaView item views from the dataSource and refreshes the display.

	func revertAction()

Applies undo animation and decrement currentCardNumber.

	func applyAppearAnimation()

Applies appear animation.

	func swipeLeft() 

Applies swipe left animation and action, increment currentCardNumber.

	func swipeRight()

Applies swipe right animation and action, increment currentCardNumber.

Protocols

The KolodaView follows the Apple convention for data-driven views by providing two protocol interfaces, KolodaViewDataSource and KolodaViewDelegate. The KolodaViewDataSource protocol has the following methods:

	func kolodaNumberOfCards(koloda: KolodaView) -> UInt

Return the number of items (views) in the KolodaView.

	func kolodaViewForCardAtIndex(koloda: KolodaView, index: UInt) -> UIView

Return a view to be displayed at the specified index in the KolodaView.

   func kolodaViewForCardOverlayAtIndex(koloda: KolodaView, index: UInt) -> OverlayView?

Return a view for card overlay at the specified index. For setting custom overlay action on swiping(left/right), you should override didSet of overlayState property in OverlayView. (See Example)

The KolodaViewDelegate protocol has the following methods:

    func kolodaDidSwipeCardAtIndex(koloda: KolodaView,index: UInt, direction: SwipeResultDirection)

This method is called whenever the KolodaView swipes card. It is called regardless of whether the card was swiped programatically or through user interaction.

    func kolodaDidRunOutOfCards(koloda: KolodaView)

This method is called when the KolodaView has no cards to display.

	func kolodaDidSelectCardAtIndex(koloda: KolodaView, index: UInt)

This method is called when one of cards is tapped.

    func kolodaShouldApplyAppearAnimation(koloda: KolodaView) -> Bool

This method is fired on reload, when any cards are displayed. If you return YES from the method, or don't implement it, the koloda will apply appear animation.

Release Notes

Version 1.0

  • Release version.

License

The MIT License (MIT)

Copyright © 2015 Yalantis

Permission is hereby granted free of charge to any person obtaining a copy of this software and associated documentation files (the "Software") to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

About

Fork of Koloda

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published