BDShelfStackViewController 0.0.5

BDShelfStackViewController 0.0.5

norsez 维护。



BDShelfStackViewController

CI Status Version License Platform

它是用来做什么的?

表格中的表格 – 简单的方法。在同一页上混合垂直和水平滚动的表格。专为快速原型设计和发布需要产品或内容浏览的应用程序而构建,例如购物或展示应用程序。

示例应用程序

Screen Capture

如何使用

本版 BDShelfStackViewController 只能通过编程方式使用。(不支持 Interface Builder)。以下是使用方法。

BDShelfStackViewController 基于定义每行的 BDSSVData 构建,垂直或水平可滚动。每个行显示的项的代理基于 BDSSVRow

什么是货架堆叠?

由于缺乏一个通用的名词,我们将表格的表格称为货架堆叠 🤷🏼‍♂️

import BDShelfStackViewController //import the library

class YourViewController: UIViewController {

    //A good place to create BDShelfStackViewController is in viewDidLoad
    override func viewDidLoad() {
        //The typical way to use BDShelfStackViewController
        //1. create a BDSSVData made of [BDSSVRow]
        //2. create BDShelfStackViewController with that BDSSVData
        //3. add the BDShelfStackViewController as a child ViewController to your main ViewController. Boom!
        let rows: [BDSSVRow] = [
            self.createDemoRow1(),
            self.createDemoRow2()
            ]
        //create data from the rows
        let data = BDSSVData(withRows: rows)
        //create shelf stack from the data above
        self.demoCtrl = BDShelfStackViewController(nibName:nil, bundle: nil)
        //assign data to and populate the shelf stacks.
        self.demoCtrl.createShelfStack(with: self.data)
        self.view.addSubview(self.demoCtrl)
        self.demoCtrol.view.frame = self.view.bounds
        //add the BDSSVShelfStackViewController as the main view's child viewcontroller
        self.addChildViewController(self.demoCtrl!)
    }
    
    //an example method to create a row
    private func createDemoRow1() {
        //BDSSVRow can be either horizontally or vertically scrollable

        var r = BDSSVRow(withType: .horizontal, 
                    itemCount: 30, 
                    rowHeight: 100)
        //define the size of each item 
        r.itemSize = CGSize(width: 120, height: 100)
        
        //define a block to return a UIView representing each item
        r.viewAtIndex = {
            index in
            let v = CellA(frame: CGRect(x: 0, y: 0, width: 120, height: 100))
            let item = DemoEngine.shared.nextItem
            v.imageView.image = item?.thumbnail
            v.titleLabel.attributedText = "\(item?.name ?? "")".attrText(with: 12)
            v.subtitleLabel.text = item?.artist ?? ""
            return v
        }
        
        //define the action when tapping each item
        r.didTapItem = { index in  }
        
        //there are a few more block variables used to customize each item's behavior and appearance in BDSSVRow
        return r
    }
    
    func reloadSecondStack() {
       //force reload a stack at index 1
       self.demoCtrl.reloadRow(at: 1, flash: true)
    }
}
    
    //That's it! Check out the sample project for a more detailed sample implementation
    

试用 README.playground(需要 Xcode 10)来了解如何使用 BDShelfStackViewController 的交互式教程。

0.0.5有新功能

  • 添加 README.playground

0.0.4有新功能

  • 移除 init(withData:)。现在使用 createShelfStack(with:) 来初始化货架堆叠视图
  • 添加方法来重新加载指定索引的堆叠 - reloadRow(at:,flash:)
  • 添加 replaceRow(at:,with:) 用于替换 BDSSVRow,如果在需要完全改变堆叠行的行为和外观时。该方法每次调用都会以高昂的代价重新创建整个货架堆叠视图。
  • 在示例项目中添加 AutoupdatedMixedViewController 以演示 reloadRow(at:,flash:) 的使用

示例

要运行示例项目,请先克隆存储库,然后从 Example 目录中运行 pod install

要求

安装

BDShelfStackViewController 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'BDShelfStackViewController'

作者

norsez, [email protected]

许可

BDShelfStackViewController符合MIT许可。有关更多信息,请参阅LICENSE文件。