测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可 | MIT |
发布最后发布 | 2017年4月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Zeke Abuhoff 维护。
Swipey 是 Zeke Abuhoff 编写的简单滑动卡片库。通过滑动卡片库,我意思是它提供了一个可以滑动的 UI 元素。就像在 Tinder 上那样。
要立即看到 Swipey 在 action 中的效果,请查看此仓库中包含的示例项目。
Swipey 提供了两个 UIView 子类来构建您的滑动界面: SwipeCard
和 SwipeDeck
。每个 SwipeCard
实例都是用户可以滑动一项或另一项的项目。 SwipeDeck
是包含多个卡片并管理当前显示哪个卡片的元素。
要开始,您可以通过代码或在 Interface Builder 中实例化一个 SwipeDeck
,就像任何 UIView
子类一样。
let swipeDeck = SwipeDeck(frame: CGRect(x: 20, y: 20, width: 300, height: 300))
为了确定要显示哪张卡片,SwipeDeck
实例依赖于一个委托,就像 UITableView
一样。
swipeDeck.delegate = self
被设置为委托的任何对象都必须遵循 SwipeDeckDelegate
协议。该协议包含四个委托方法。
// The SwipeDeck will call the method below to determine how many cards are in the deck.
func numberOfCards(swipeDeck: SwipeDeck) -> Int {
// Return the number of cards you'll need for your swipe deck
return 5
}
// The SwipeDeck will call the method below whenever it needs to display a new card.
func cardFor(index: Int, swipeDeck: SwipeDeck) -> SwipeCard {
// Produce a swipe card, like dequeueing a table view cell
let swipeCard = swipeDeck.produceSwipeCard()
// Customize the swipe card
swipeCard.backgroundColor = UIColor.blue
// Return the swipe card
return swipeCard
}
// The SwipeDeck will call the method below when the user swipes in a positive direction.
func positiveSwipe(swipeDeck: SwipeDeck) {
// React to a positive swipe
print("positive swipe")
}
// The SwipeDeck will call the method below when the user swipes in a negative direction.
func negativeSwipe(swipeDeck: SwipeDeck) {
// React to a negative swipe
print("negative swipe")
}
一旦您定义了委托方法并设置了卡组的委托,卡组将自动显示委托方法指定的内容。