📑 SHEET 帮助你轻松创建各种带有导航功能的 Action Sheet,就像 Flipboard App 里那样
pod 'Sheet', '~> 0.7.0'
github "ParkGwangBeom/Sheet" ~> 0.7.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)来使用自定义的 Action Sheet 过渡效果。
🔥 但是,不要使用 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)
请查看示例项目了解更多细节。
Sheet 基本上具有导航结构。所有子视图都应该继承自 SheetContentsViewController。SheetContentsViewController 默认继承自 UICollectionViewController,其布局如下图所示。
请参考示例代码了解图像布局的详细设置。
通过 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)? |
属性 | 类型 |
---|---|
sheetToolBar |
UIView |
方法 | 说明 |
---|---|
func registCollectionElement() |
让 CollectionView 有机会调整 Supplementray Element |
func setupSheetLayout() |
提供一个机会来设置 collectionview 自定义布局的默认设置 |
func reload() |
帮助重新加载 CollectionView 并调整内容的高度。 |
func close(completion: (() -> Void)? = nil) |
Sheet 关闭 |
内置工具栏由单个按钮组成。
默认工具栏 |
---|
![]() |
设置自定义工具栏非常简单。
sheetToolBar = CustomToolBar()
Sheet 使用 MIT 许可证发布。 有关详细信息,请参阅 LICENSE。