【发布时间】:2015-10-12 09:02:50
【问题描述】:
我正在使用 Koloda 库 (https://github.com/Yalantis/Koloda) 在 Tinder 类似卡片的滑动视图中显示数据。
import UIKit
import Koloda
import pop
import Parse
import Bolts
import ParseUI
private var numberOfCards: UInt = 5
class ViewController: UIViewController, KolodaViewDataSource, KolodaViewDelegate {
var ids : [String] = []
@IBOutlet weak var kolodaView: KolodaView!
@IBAction func undo(sender: AnyObject) {
kolodaView?.revertAction()
}
@IBAction func left(sender: AnyObject) {
kolodaView?.swipe(SwipeResultDirection.Left)
}
@IBAction func right(sender: AnyObject) {
kolodaView?.swipe(SwipeResultDirection.Right)
}
override func viewDidLoad() {
super.viewDidLoad()
kolodaView.dataSource = self
kolodaView.delegate = self
self.modalTransitionStyle = UIModalTransitionStyle.FlipHorizontal
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//MARK: KolodaViewDataSource
func kolodaNumberOfCards(koloda: KolodaView) -> UInt {
return numberOfCards
}
func kolodaViewForCardAtIndex(koloda: KolodaView, index: UInt) -> UIView {
return UIImageView(image: UIImage(named: "Card_like_\(index + 1)"))
}
func kolodaViewForCardOverlayAtIndex(koloda: KolodaView, index: UInt) -> OverlayView? {
return NSBundle.mainBundle().loadNibNamed("OverlayView",
owner: self, options: nil)[0] as? OverlayView
}
//MARK: KolodaViewDelegate
func kolodaDidSwipedCardAtIndex(koloda: KolodaView, index: UInt, direction: SwipeResultDirection) {
//Example: loading more cards
if index >= 3 {
numberOfCards = 6
kolodaView.reloadData()
}
}
func kolodaDidRunOutOfCards(koloda: KolodaView) {
//Example: reloading
kolodaView.resetCurrentCardNumber()
}
func kolodaDidSelectCardAtIndex(koloda: KolodaView, index: UInt) {
UIApplication.sharedApplication().openURL(NSURL(string: "http://yalantis.com/")!)
}
func kolodaShouldApplyAppearAnimation(koloda: KolodaView) -> Bool {
return true
}
func kolodaShouldMoveBackgroundCard(koloda: KolodaView) -> Bool {
return true
}
func kolodaShouldTransparentizeNextCard(koloda: KolodaView) -> Bool {
return true
}
func kolodaBackgroundCardAnimation(koloda: KolodaView) -> POPPropertyAnimation? {
return nil
}
}
上面的代码适用于我存储在 Assets 中的六张图片。我想要的是用 ParseUser (文本和图像)中的数据填充每张卡片。我一直在考虑用 ParseData 填充 tableView 的类似方法,但我找不到正确的解决方案。这就是 KolodaView 的目的:
KolodaView 是一个类,旨在简化 iOS 上类似 Tinder 的卡片的实现。它添加了方便的功能,例如用于动态加载视图的 UITableView 样式的 dataSource/delegate 接口,以及高效的视图加载、卸载。
也许有另一个图书馆可以做同样的事情。
【问题讨论】:
标签: ios swift parse-platform swift2 swipe