Sheet 0.7.0

Sheet 0.7.0

gwangbeom维护。



Sheet 0.7.0

  • 作者
  • gwangbeom

Logo

Swift 4.0+ iOS 9.0 Version Carthage Compatible Platform License


📑SHEET帮助您轻松创建各种带有导航功能的action sheets,这些功能用于Flipboard应用中


Example

安装

CocoaPods

pod 'Sheet', '~> 0.6.0'

Carthage

github "ParkGwangBeom/Sheet" ~> 0.6.0

手动

如果您不想使用上述任何依赖管理器,您可以手动将Sheet集成到项目中。

使用方法

实现Sheet的内容类似于实现现有的UICollectionViewController。只需让您的视图控制器继承自SheetContentsViewController。

import Sheet

class ViewController: SheetContentsViewController {

   /// Sheet visible contents height. If contentSize height is less than visibleContentsHeight, contentSize height is applied.
    override var visibleContentsHeight: CGFloat {
        return 600
    }
    
    /// Give CollectionView a chance to regulate Supplementray Element
    override func registCollectionElement() {
        let nib = UINib(nibName: "TitleHeaderView", bundle: nil)
        collectionView?.register(nib, forSupplementaryViewOfKind: SheetLayoutElement.header.kind, withReuseIdentifier: SheetLayoutElement.header.id)
    }

    /// Provide an opportunity to set default settings for collectionview custom layout
    override func setupSheetLayout(_ layout: SheetContentsLayout) {
        layout.settings.itemSize = { indexPath in
            let height: CGFloat = indexPath.section == 0 ? 30 : 60
            return CGSize(width: UIScreen.main.bounds.width, height: height)
        }
        layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 15, right: 0)
        layout.settings.headerSize = CGSize(width: UIScreen.main.bounds.width, height: 60)
        layout.settings.isHeaderStretchy = true
    }
    
   override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }
    
    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
         ...
        return cell
    }
    
    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
         ...
    }
   
     ...
}

您可以使用UIKit提供的默认API,如present、push、pop来使用自定义动作表单过渡。

🔥 但是,不要使用NavigationController的dismiss方法,而是使用close (duration: completion:) 函数。

// present
let contentsViewController = ViewController()
let sheetNavigation = SheetNavigationController(rootViewController: contentsViewController)
present(sheetNavigation, animated: true, completion: nil)

// push
let nextContentsViewController = NextContentsViewController()
navigationController?.pushViewController(nextContentsViewController, animated: true)

// pop
navigationController?.popViewController(animated: true)

请参见示例项目以获取更多详细信息。

布局

动作表单基本上具有导航结构。所有子类都应继承自SheetContentsViewController。SheetContentsViewController默认继承自UICollectionViewController,其布局如下所示。

layout

请参考示例代码以获取图像布局的详细设置。

高级

通过SheetContents轻松自定义。

选项

属性 类型 默认值
defaultToolBarBackgroundColor UIColor .black
sheetToolBarHeight CGFloat 50
isSheetToolBarHidden Bool false
cornerRadius CGFloat 0
defaultVisibleContentHeight CGFloat 240
dimmingViewBackgroundColor UIColor .black.withAlphaComponent(0.3)
sheetBackgroundColor UIColor .white
presentTransitionType SheetPresentTransitionType .scale

布局设置

属性 类型
headerSize CGSize?
footerSize CGSize?
itemSize ((IndexPath) -> CGSize)?
sectionHeaderSize ((IndexPath) -> CGSize)?
sectionFooterSize ((IndexPath) -> CGSize)?

SheetContentsViewController

属性 类型
sheetToolBar UIView
方法 说明
func registCollectionElement() 为CollectionView提供调整补充元素的机会
func setupSheetLayout() 提供设置自定义集合视图布局的默认设置的机会
func reload() 帮助重新加载CollectionView并调整内容的长度。
func close(completion: (() -> Void)? = nil) 关闭工作表

自定义工具栏

内置工具栏由一个按钮组成。

默认工具栏

设置自定义工具栏非常简单。

sheetToolBar = CustomToolBar()

作者

许可

工作表是在MIT许可证下发布的。详细信息请参见LICENSE。