V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
newkengsir
V2EX  ›  Apple

卡片容器 SwipeableCards

  •  
  •   newkengsir · 2016-11-07 09:55:25 +08:00 · 1937 次点击
    这是一个创建于 2937 天前的主题,其中的信息可能已经有所发展或是发生改变。

    A container of views (like cards) can be dragged!

    视图容器,视图以卡片形式层叠放置,可滑动。

    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

    图片描述

    图片描述

    图片描述

    Usage:

    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)")
        }
    
    
    1 条回复    2016-11-07 10:06:44 +08:00
    YzSama
        1
    YzSama  
       2016-11-07 10:06:44 +08:00
    已收藏。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3435 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 10:31 · PVG 18:31 · LAX 02:31 · JFK 05:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.