MantleModal 《1.0.0》

MantleModal 《1.0.0》

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2015年11月
SPM支持SPM

Ricardo Canales维护。




MantleModal 《1.0.0》

  • Ricardo Canales

Mantle Modal

可拖拽的模态框,弹出或菜单

描述

一个使用UIScrollView的简单模态资源,允许用户通过向下拖动来关闭模态框。

安装指南

手册

将名为RCMantleViewController.swift的文件拖到您的项目中。

使用

设置非常简单,但我计划稍后使其更简单。

步骤 1

在Storyboard中添加新的ViewController,将Class设置为RCMantleViewController,将Storyboard ID设置为MantleViewController

步骤 2

在Storyboard中添加您自己的视图,该视图代表模态框。还要为它设置一个唯一的Storyboard ID

如果您要使用弹出窗口,请设置背景视图颜色为透明。

步骤 3

将模块导入到您的父控制台(如果使用CocoaPods)

  import MantleModal

在父控制台中按如下方式激活模态框。

  // Create the MantleViewController from the Storyboard using the ID
  let mantleViewController = storyboard!.instantiateViewControllerWithIdentifier("MantleViewController") as! RCMantleViewController
  // Create your modal controller with your storyboard ID
  let popUpViewController = storyboard!.instantiateViewControllerWithIdentifier("YourUniqueStoryboardID") as! YourViewController
  // Set it's delegate to be able to call 'delegate.dismissView(animated: Bool)'
  popUpViewController.delegate = mantleViewController
  // Initialize Mantle
  mantleViewController.setUpScrollView()
  // Add your modal to Mantle
  mantleViewController.addToScrollViewNewController(popUpViewController)
  // Present the modal through the MantleViewController
  self.presentViewController(mantleViewController, animated: false, completion: nil)

步骤 4

在模态框的控制器中,也导入以下内容

  import MantleModal

然后定义您的代理助手。

  var delegate: RCMantleViewDelegate!

然后使用此方法关闭模态框

  delegate.dismissView(true)

选项

MantleModal目前包含一些配置,您必须在使用mantleViewController.setUpScrollView之前调用。当前可用的配置包括

  // Allows you to dismiss the view by dragging up
  mantleViewController.bottomDismissible = false
  // Allows you to dismiss the view by dragging down
  mantleViewController.topDismissable = true
  // Allows you to drag to the sides to close
  mantleViewController.draggableToSides = false

  // 'appearOffset' moves the menu closer to the edge so that it appears quicker
  mantleViewController.appearOffset = CGFloat(290)
  // '290' could be the distance between the top of the popup and the top of the screen 

  // Makes the view present from the top, can be set multiple times before presenting
  // Also makes it hide to the top.
  mantleViewController.appearFromTop = true // // default = false

您还可以访问UIScrollView并修改其选项,只需确保在调用mantleViewController.setUpScrollView后执行即可。

  mantleViewController.scrollView.bounces = false

鸣谢

主要由我完成 - Ricardo Canales

最初的代码灵感来源于这个StackOverflow帖。向lbrendanlPoql致谢