我使用Koloda库(https://github.com/Yalantis/Koloda)像卡片一样在刷视图中显示数据。
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
}
}上面的代码可以很好地处理我存储在资产中的六个图像。我想要的是用ParseUser (文本和图像)的数据填充每一张卡片。我一直在考虑类似于用tableView填充ParseData,但我找不到正确的解决方案。这就是KolodaView的目的:
KolodaView是一个类,旨在简化Tinder的实现,就像iOS上的卡片一样。它增加了方便的功能,如UITableView风格的dataSource/委托接口,用于动态加载视图,以及高效的视图加载、卸载。
也许还有另一个库也可以这样做。
https://stackoverflow.com/questions/33077146
复制相似问题