Modamic 0.0.2

Modamic 0.0.2

Daniel 维护。



Modamic 0.0.2

Modamic

xcodebuild

轻量级库,用于在模态视图(UIViewController)中展现。

⚠️该库处于开发中(WIP),如果您发现任何错误,请创建问题或拉取请求。

预览

Preview Preview Preview

特性🎉

  • 自动处理键盘
  • 运行时动态调整大小
  • 可自定义配置
  • 垂直位置
  • 自定义动画转换
  • 支持 UINavigationController
  • 支持协调模式

用法

可用的垂直位置

  • 顶部
  • 中部
  • 底部

配置

有一个默认的 ModemicConfiguration,但您也可以创建一个自定义配置。以下列出可用的属性:

    /// The presented controller have rounded corners.
    public var roundCorners: Bool = true
    
    /// Radius of rounded corners for presented controller if roundCorners is true.
    public var cornerRadius: CGFloat = 10
    
    /// Keyboard shows animation duration
    public var showKeyboardAnimationDuration: TimeInterval = 0.5
    
    /// Keyboard hiding animation duration
    public var hideKeyboardAnimationDuration: TimeInterval = 0.5
    
    /// Non notch device bottom spacing
    public var nonNotchBottomSpacing: CGFloat = 20
    
    /// Non notch device top spacing
    public var nonNotchTopSpacing: CGFloat = 20
    
    /// Automatically dismisses keyboard if the viewController is dismissed
    public var autoDismissKeyboard: Bool = true
    
    /// Background color of the dimmed backgroundView
    public var dimmingViewBackgroundColor = UIColor(white: 0, alpha: 0.4)
    
    /// Cutomize the animation of the contentSize resizing
    public var contentSizeChangedAnimationOptions: AnimationSettings = (duration: 0.3, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 15)

    /// Tap on the backgroundView automatically dismisses the ViewController
    public var autoDismissOnBackgroundTap: Bool = true
    
    /// Vertical position of the viewController
    public var modalVerticalPosition: ModalVerticalPosition = .bottom
    
    /// Width of the modal viewController
    public var modalWidth: ModalWidth = .parentFactor(0.9)
    
    /// Animated transition for the modal
    public var animatedTransition: AnimatedTransition = .bottom

运行时调整大小

该库支持AutoLayout,所以如果您添加/删除某些视图或更改子视图的高度,只需要调用UIViewController的setPreferredContentSizeFromAutolayout()方法。这将重新计算高度并动画调整大小的模态 - 请参阅示例项目。

宽度

定义模态宽度有两种方法

  • 动态:使用一个因子缩放父ViewController的宽度
  • 固定:为模态设置一个固定宽度

动画过渡

您可以使用默认的(从底部推送)动画,也可以使用顶部动画来显示模态。但还有一个custom(forPresented: UIViewControllerAnimatedTransitioning, forDismissed: UIViewControllerAnimatedTransitioning)情况,可以用于使用自定义动画。

示例

    let modamicConfig = ModamicConfiguration()
    modamicConfig.autoDismissKeyboard = false
    modamicConfig.modalVerticalPosition = .center

    let presenter = ModamicPresenter(configuration: modamicConfig)
    presenter.presentModal(viewController: updateViewController, on: self, completion: nil)

待办事项

  • 当内容大于屏幕时使用scrollView
  • 处理旋转

安装

CocoaPods

pod "Modamic"

要求

  • Swift 5
  • iOS 9