A container of views (like cards) can be dragged!
视图容器,视图以卡片形式层叠放置,可滑动。
There are only visible cards in memory, after you drag and removed the top one, it will be reused as the last one. 内存中只会生成可见的卡片,顶部的卡片被划走之后,会作为最后一张卡片循环利用。
项目详情介绍: 网页地址
Objective-C version here:
Objective-C 版:iCards
Swift version here:
Swift 版:SwipeableCards



Usage:
Here is an example:
用法示例:
@IBOutlet weak var cards: SwipeableCards!
var cardsData = [Int]()
override func viewDidLoad() {
super.viewDidLoad()
makeCardsData()
cards.dataSource = self
cards.delegate = self
}
func makeCardsData() {
for i in 0..<100 {
cardsData.append(i)
}
}
// SwipeableCardsDataSource methods
func numberOfTotalCards(in cards: SwipeableCards) -> Int {
return cardsData.count
}
func view(for cards: SwipeableCards, index: Int, reusingView: UIView?) -> UIView {
var label: UILabel? = reusingView as? UILabel
if label == nil {
let labelFrame = CGRect(x: 0, y: 0, width: cardsWidth.constant - 30, height: cardsHeight.constant - 20)
label = UILabel(frame: labelFrame)
label!.textAlignment = .center
label!.layer.cornerRadius = 5
}
label!.text = String(cardsData[index])
label!.layer.backgroundColor = Color.random.cgColor
return label!
}
// SwipeableCardsDelegate methods
func cards(_ cards: SwipeableCards, beforeSwipingItemAt index: Int) {
print("Begin swiping card \(index)!")
}
func cards(_ cards: SwipeableCards, didLeftRemovedItemAt index: Int) {
print("<--\(index)")
}
func cards(_ cards: SwipeableCards, didRightRemovedItemAt index: Int) {
print("\(index)-->")
}
func cards(_ cards: SwipeableCards, didRemovedItemAt index: Int) {
print("index of removed card:\(index)")
}