agordeev / OverlayViewController

A simple way to present your child view controller on top of another one

Home Page:https://andreygordeev.com/2017/04/18/overlay-view-controller-protocols-swift/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OverlayViewController

A simple way to present your child view controller on top of another one. Read relevant article: https://andreygordeev.com/2017/04/18/overlay-view-controller-protocols-swift/.

Written on Swift.

Usage

Parent view controller

Make the parent view controller conforming to OverlayHost protocol and call showOverlay(_:) method when needed:

class ViewController: UIViewController, OverlayHost {
    @IBAction func showOverlayButtonPressed() {
        showOverlay(type: MessageViewController.self, fromStoryboardWithName: "Main")
    }
}

Overlay view controller

Make the parent view controller conforming to OverlayViewController protocol and call dismissOverlay() method when you want to dismiss the overlay:

class MessageViewController: UIViewController, OverlayViewController {
    let overlaySize: CGSize? = CGSize(width: UIScreen.main.bounds.width * 0.8, height: 120.0)
    @IBAction func closeButtonPressed() {
        dismissOverlay()
    }
}

On storyboard, set view controller's Storyboard ID to MessageViewController.

Installation

Just drop OverlayViewController.swift into your project and you're all set.

Author

Andrey Gordeev

License

This project is under MIT license. For more information, see LICENSE file.

About

A simple way to present your child view controller on top of another one

https://andreygordeev.com/2017/04/18/overlay-view-controller-protocols-swift/

License:MIT License


Languages

Language:Swift 100.0%