FloatingBottomSheet

Logo

Build Status Swift Package Manager compatible Swift Versions Platform

一个显示浮动底部 sheet 的库。

请参阅托管在 Swift Package Index 上的 FloatingBottomSheet DocC 文档

兼容性

FloatingBottomSheet 需要 iOS 11+ 版本,并兼容 Swift 5 项目。

安装

Swift Package Manager.

安装 FloatingBottomSheet 的首选方式是通过 Swift Package Manager

  1. 在 Xcode 中,打开你的项目并导航到 FileAdd Packages
  2. 粘贴仓库 URL (https://github.com/OhKanghoon/FloatingBottomSheet) 并点击 Next
  3. 对于 Rules,选择 Up to Next Major Version
  4. 点击 Add Package

CocoaPods

# Podfile
use_frameworks!

target 'YOUR_TARGET_NAME' do
  pod 'FloatingBottomSheet'
end

替换 YOUR_TARGET_NAME,然后在 Podfile 目录中,输入

$ pod install

用法

Preview

配置

要使用 FloatingBottomSheet,你的 ViewController 必须遵循 FloatingBottomSheetPresentable 协议。

首先实现 bottomSheetScrollablebottomSheetHeight 属性。

final class ViewController: UIViewController, FloatingBottomSheetPresentable {
  
  var bottomSheetScrollable: UIScrollView? { 
    // Return a scrollable view
  }
    
  var bottomSheetHeight: CGFloat { 
    // Set the height of the bottom sheet
  }
}

呈现底部 sheet

只需使用 presentFloatingBottomSheet 函数即可呈现浮动底部 sheet,如下所示

let viewController = ViewController()

presentFloatingBottomSheet(viewController)

在运行时更新底部 sheet 高度

要在运行时动态更新底部 sheet 的高度,请使用以下代码

bottomSheetHeight = 400.0
bottomSheetPerformLayout(animated: true)

你可以将 bottomSheetHeight 的值更改为你想要的高度,然后调用 bottomSheetPerformLayout 函数以更新底部 sheet 的高度,并可选择动画。

如果你不想要动画,请将 animated 设置为 false。

许可

FloatingBottomSheet 基于 MIT 许可。有关更多信息,请参阅 LICENSE