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
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)")
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.