JModalController 0.2.0

JModalController 0.2.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布日期最新发布2016年9月
SPM支持 SPM

Mark JacksonMark Jackson 维护。




JModalController

制作自定义模态框的一种简单而优秀的方法。

*⚠️ 用于 Swift 2.3 的使用,请使用 0.1 版本。 发布 **⚠️

*⚠️ 用于 Swift 3.0 的使用,请使用 0.2 或更高版本的发布。 **⚠️

*⚠️ 本 Readme 使用了 Swift 3.0 版本,查找旧 Readme 以查看旧 API *EMY⚠️

JModalController

运行示例

要运行示例项目,首先克隆仓库,然后从 Example 目录运行 pod install

要求

JModalController 要求 iOS 8 或更高版本。

安装

JModalController 通过 CocoaPods 提供。为了安装它,请简单地将其添加到 Podfile 中。

pod 'JModalController'

使用

创建一个与任何其他故事板控制器一样的故事板控制器。

Create ViewController in storyboard

根据需要调整控制器的大小。宽度和高度都可以短于呈现的视图控制器。

Size the modal

注意:请确保取消选中“从 NIB 调整视图大小”,否则模态框将不是您的自定义大小。如果不取消选中此选项,则必须在呈现模态框之前手动设置框架。

Uncheck Resize View From NIB

使用 Storyboard,您只需加载控制器并调用 presentModal()

#import JModalController

// ...

func showModal() {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let simpleVC = storyboard.instantiateViewControllerWithIdentifier("SimpleModalViewController") as? SimpleModalViewController

    //Set the delegate in order to dismiss the modal
    simpleVC?.delegate = self

    //Set configuration settings to customize how the modal presents
    let config = JModalConfig(animationDuration: 0.2, tapOverlayDismiss: true, transitionDirection: .Bottom, backgroundTransform: true)

    //Present the modal!
    //`self` if no navigation or tabBar controllers are present!
    presentModal(self, modalViewController: simpleVC!, config: config) {
        print("Presented Simple Modal")
    }
}

注意: presentModal 需要一个 basePresentingViewController。此控制器应该是您要进行转换的基本控制器。因此,如果有您的控制器嵌入到 UINavigationController 和/或 UITabBarController 中,请使用 navigationController/tabBarController 而不是 self

处理模态框很简单,只需调用 delegate.dismissModal(self, nil)

import JModalController

var delegate : JModalDelegate?

// ...

@IBAction func dismiss(sender: AnyObject) {
  //Dismiss Modal, give the data parameter anything you want to send back to the presenting view controller.  
  self.delegate!.dismissModal(self, data: nil)
}

JModalConfig

JModalConfig 是一个允许自定义模态框的类。属性描述动画长度、背景动画颜色等。

以下是可自定义的属性。可以通过初始化器或手动设置属性。有关这些属性的功能,请查看演示项目。

/// Background color of the overlay that covers your current view controller. Default set to UIColor(white: 0, alpha: 0.3)
public var overlayBackgroundColor: UIColor

/// Direction where you want the modal to appear from. Default set to .Bottom
public var transitionDirection: JModalTransitionDirection

/// View animation options for how to have modal and overlay to appear. Default set to .CurveLinear
public var animationOptions: UIViewAnimationOptions

/// Duration on how long views animate on appearing and dismissing. Default set to 0.3
public var animationDuration: NSTimeInterval

/// The 0 - 1 value of how much the background viewcontroller transforms on modal appearance. Default set to 0.93
public var backgroundTransformPercentage: Double

/// Boolean indicating of background viewcontroller should transform on modal appearance. Default set to true
public var backgroundTransform: Bool

/// Boolean indicating if tapping on the background overlay should dismiss modal. Default set to true
public var tapOverlayDismiss: Bool

///Swipe gesture directions you want your modal to support for dismissing. Default set to []
public var swipeDirections: [UISwipeGestureRecognizerDirection]

JModalDelegate

自动导入 pod 会使 UIViewController 遵守 JModalDelegate 协议。重写 dismissModal 方法可以获取模态视图返回的数据。

待办事项

  • 测试
  • 更高的可定制性
  • Rx 版本

贡献

任何人都可以通过查找问题或提交任何 pull request 来帮助改进 JModalController。

作者

Mark Jackson, [email protected]

许可证

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