V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
newkengsir
V2EX  ›  Apple

卡片容器 SwipeableCards

  •  
  •   newkengsir · Nov 7, 2016 · 2490 views
    This topic created in 3472 days ago, the information mentioned may be changed or developed.

    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 replies    2016-11-07 10:06:44 +08:00
    YzSama
        1
    YzSama  
       Nov 7, 2016
    已收藏。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5714 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 08:47 · PVG 16:47 · LAX 01:47 · JFK 04:47
    ♥ Do have faith in what you're doing.