几个月前我刚开始使用 Swift 编程,所以为了帮助我学习,我正在做一个类似于Tinder
using Koloda View
. 我使用 Firebase 作为我的后端。我在下面包含的代码适用于卡片的 6 个图像资产,但我正在尝试找出一种方法来为每个用户创建一张卡片并将这些自定义卡片用作KolodaView
.
我创建了一个XIB
文件用作这些卡片的模板,但我不确定如何从数据库中的每个用户那里获取信息以显示在这些卡片上。另外,如何实例化XIB
文件的多个副本以供每个用户使用?
很抱歉这个问题的措辞令人困惑,因为我只是一个初学者,我在试图表达我的问题时遇到了麻烦。请问我您是否需要对我要说的内容进行澄清。
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.
}
//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
}
}