To run the example project, clone the repo and run pod install
from the Example directory first.
- iOS 8 or later
- Swift 4.0
KKSwipeCards is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "KKSwipeCards"
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)
}
To add new cards, just call the addCards
method with an array of the previously defined Element
:
swipeView.addCards([String: String], onTop: true)
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.
For a nice working demo sample, please take a look the Example project.
Run pod install
to run the example in the Example
directory.
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
Vinoth Anandan, kkvinokk@gmail.com
Bug reports and pull requests are welcome on GitHub at https://github.com/kkvinokk/KKSwipeCards.
KKSwipeCards is available under the MIT License. See the License file for more info.