Latest | 0.1.1 |
---|---|
Homepage | https://github.com/kkvinokk/KKSwipeCards |
License | MIT |
Platforms | ios 8.0 |
Authors |
Example
To run the example project, clone the repo and run pod install
from the Example directory first.
Requirements
- iOS 8 or later
- Swift 4.0
Installation
KKSwipeCards is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "KKSwipeCards"
How to use
First import the module:
import KKSwipeCards
Next create an instance of a KKSwipeCardsView
:
(Element
can be your custom model, or just [String: String]
)
let swipeView = KKSwipeCardsView<Element>(frame: frame,
viewGenerator: viewGenerator,
overlayGenerator: overlayGenerator)
Views get loaded lazy, so you have to provide KKSwipeCardsView
with a ViewGenerator and optionally an OverlayGenerator.
let viewGenerator: ([String: String], CGRect) -> (UIView) = { (element: [String: String], frame: CGRect) -> (UIView) in
// return a Card(UIView)
}
let overlayGenerator: ([String: String], SwipeMode, CGRect) -> (UIView) = { (element: [String: String], mode: SwipeMode, frame: CGRect) -> (UIView) in
// return a Overlay design(UIView)
}
Adding cards
To add new cards, just call the addCards
method with an array of the previously defined Element
:
swipeView.addCards([String: String], onTop: true)
Delegate
KKSwipeCardsView
has a delegate property so you can get informed when a card has been swiped. The delegate has to implement following methods:
func swipedLeft(_ object: Any)
func swipedRight(_ object: Any)
func swipedTop(_ object: Any)
func swipedBottom(_ object: Any)
func cardTapped(_ object: Any)
func reachedEndOfStack()
The object
parameter is guaranteed to have the type Element
. Making Element
as generics in delegate will increase complexity.
Example
For a nice working demo sample, please take a look the Example project.
Run pod install
to run the example in the Example
directory.
Credits
Added features over DMSwipeCards
- Swipe top and bottom
- Passing data in
overlayGenerator
- Card won’t swipe if user touch in scrollView part of card (In GestureRecognizer, shouldRecognizeSimultaneouslyWith is made false)
- Example with retaining the previous card when swiping in bottom
Author
Vinoth Anandan, [email protected]
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/kkvinokk/KKSwipeCards.
License
KKSwipeCards is available under the MIT License. See the License file for more info.
Latest podspec
{ "name": "KKSwipeCards", "version": "0.1.1", "summary": "Tinder like card interface with four side swipe.", "description": "Written in Swift 4, supports custom views for the card and the overlay. Views get loaded lazily, so there's no issues in loading a huge amount of cards.", "homepage": "https://github.com/kkvinokk/KKSwipeCards", "license": { "type": "MIT", "file": "LICENSE" }, "authors": { "Vinoth Anandan": "[email protected]" }, "source": { "git": "https://github.com/kkvinokk/KKSwipeCards.git", "tag": "0.1.1" }, "platforms": { "ios": "8.0" }, "source_files": "KKSwipeCards/Classes/**/*", "pushed_with_swift_version": "4.0" }
Mon, 30 Oct 2017 10:20:13 +0000