SFBottomSheet 0.0.11

SFBottomSheet 0.0.11

由以下人员维护:Aleksandar GyuzelovDimitar Petrovdimitar.petrovKostadin Zamanov



  • scalefocus

SFBottomSheet

Version Platform License

SFBottomSheet 是一个屏幕底部锚定、便于拇指操作的交互视图的自定义模态表示样式实现

如何安装

pod 'SFBottomSheet'
import SFBottomSheet

开发者指南

每个 SFBottomSheet 接受一个子视图控制器,该控制器必须符合 SFBottomSheetChildControllerProtocol。通过此协议,每个子视图控制器描述了如何表示。

public protocol SFBottomSheetChildControllerProtocol: UIViewController {
    
    var delegate: SFBottomSheetChildDelegate? { get set }
    var defaultContainerHeight: CGFloat { get set }
    var minimumAvailableContainerHeight: CGFloat { get }
    var maximumAvailableHeightCoefficient: CGFloat { get }
    var childContainerLeadingDefaultConstraint: CGFloat { get }
    
    func getContainerHeight(_ maximumAvailableContainerHeight: CGFloat) -> CGFloat

}

public protocol SFBottomSheetChildDelegate: class {
    
    func childDidChangeHeight(with height: CGFloat)
    func childDidRequestClose()

}

SFBottomSheet 还接受一个必须符合 SFBottomSheetConfigurable 的自定义配置

public protocol SFBottomSheetConfigurable {
    
    // MARK: Content
    
    var contentViewBackgroundColor: UIColor { get }
    
    // MARK: Container
    
    var containerViewCornerRadius: CGFloat { get }
    
    // MARK: Draggable
    
    var draggableContainerHeightConstraint: CGFloat { get }
    var draggableContainerBottomConstraint: CGFloat { get }
    var draggableHeightConstraint : CGFloat { get }
    var draggableWidthConstraint: CGFloat { get }
    var draggableBackgroundColor: UIColor { get }
    var draggableAlpha: CGFloat { get }
    var draggableCornerRadius: CGFloat { get }
    var draggableMaskedCorners: CACornerMask { get }
    
}

注意:如果不提供,将使用默认值。

struct SFBottomSheetConfigurator: SFBottomSheetConfigurable {
    
    // MARK: Content
    
    var contentViewBackgroundColor: UIColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.4)
    
    // MARK: Container
    
    var containerViewCornerRadius: CGFloat = 16
        
    // MARK: Draggable
    
    var draggableContainerHeightConstraint: CGFloat = 30
    var draggableContainerBottomConstraint: CGFloat = 0
    var draggableHeightConstraint: CGFloat = 5
    var draggableWidthConstraint: CGFloat = 40
    var draggableBackgroundColor: UIColor = .white
    var draggableAlpha: CGFloat = 1
    var draggableCornerRadius: CGFloat = 2
    var draggableMaskedCorners: CACornerMask = [.layerMinXMinYCorner, .layerMaxXMinYCorner, .layerMaxXMaxYCorner, .layerMinXMaxYCorner]

}

如何使用

  • 使用默认配置
let childViewController: SFBottomSheetChildControllerProtocol = SFBottomSheetChildViewController()
guard let bottomSheetViewController = SFBottomSheetViewController.createScene(child: childViewController,
                                                                        didFinishWithoutSelection: nil) else { return }
bottomSheetViewController.modalPresentationStyle = .overFullScreen
bottomSheetViewController.modalTransitionStyle = .crossDissolve
present(bottomSheetViewController, animated: true)
  • 使用自定义配置
let childViewController: SFBottomSheetChildControllerProtocol = SFBottomSheetChildViewController()
var let configuration: SFBottomSheetConfigurable = CustomConfiguration()
configuration.draggableAlpha = 0.7
configuration.contentViewBackgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.8)
guard let bottomSheetViewController = SFBottomSheetViewController.createScene(child: childViewController,
                                                                        configuration: configuration,
                                                                        didFinishWithoutSelection: nil) else { return }
bottomSheetViewController.modalPresentationStyle = .overFullScreen
bottomSheetViewController.modalTransitionStyle = .crossDissolve
present(bottomSheetViewController, animated: true)

有关更多示例和用法,请参阅 Wiki

更多信息

  • 如果您在打开过程中遇到任何问题,请创建问题
  • 如果您想为项目做出贡献,请发起拉取请求并说明您的更改内容。

发布历史记录

  • 0.0.1
    • 初始设置
  • 0.0.2
    • 更新 .podspec source_files
  • 0.0.3
    • 更新 SFBottomSheetViewController createScene 方法保护级别
  • 0.0.4
    • 更新 .podspec resource_bundles 修复 SFBottomSheetViewController 实例化问题
  • 0.0.6
    • 更新 .podspec 并提供 SFBottomSheetConfigurable 公共初始化器
  • 0.0.7
    • 通过更新 SFBottomSheetChildControllerProtocol 解决子前置约束问题

元数据

Aleksandar Gyuzelov – @ScaleFocus[email protected]

在 MIT 许可证下分发。有关更多信息,请参阅 LICENSE 文件。

贡献

  1. 分支并修改代码(https://github.com/scalefocus/SFBottomSheet/fork
  2. 创建功能分支(git checkout -b feature/branch-name
  3. 提交您的更改(git commit -am '描述性提交信息'
  4. 将更改推送到分支(git push origin feature/branch-name
  5. 创建新的拉取请求

贡献者