【问题标题】:Use Koloda library with Parse data source将 Koloda 库与 Parse 数据源一起使用
【发布时间】: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


    【解决方案1】:

    您可以像使用 UITableView 一样使用 Koloda。开始在 viewDidLoad 中异步获取对象,然后在回调中调用 reloadData,因此 Koloda 必须重新配置其视图。

    注意:存储库中有networking_example https://github.com/Yalantis/Koloda/tree/networking_example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-10
      • 2016-11-13
      • 1970-01-01
      • 1970-01-01
      • 2014-12-18
      • 1970-01-01
      相关资源
      最近更新 更多