Latest 2.0
Homepage https://github.com/kylebshr/ElegantPresentations
License MIT
Platforms ios 8.0, requires ARC
Frameworks UIKit
Authors

Does this need to exist? Probably not. It’s very easy to implement. But I’ve looked around for an existing presenter that animates in the same fashion as Twitter.app many times, and was never able to find one — so here it is, with a few extra options too!

ElegantPresentations

Installation

CocoaPods

use_frameworks!

pod 'ElegantPresentations'

How To Use

Add import ElegantPresentations to the top of your presenting view controller and Conform to the UIViewControllerTransitioningDelegate protocol like so:

// Conform to UIViewControllerTransitioningDelegate

func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? {
    return ElegantPresentations.controller(presentedViewController: presented, presentingViewController: presenting, options: [])
}

If you’re using storyboards

// Set the delegate on the presented view controller

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    segue.destinationViewController.modalPresentationStyle = .Custom
    segue.destinationViewController.transitioningDelegate = self
}

If you’re not using storyboards

// Set the delegate whenever you instantiate the view controller

let destinationVC = storyboard!.instantiateViewControllerWithIdentifier("Compose")

destinationVC.modalPresentationStyle = .Custom
destinationVC.transitioningDelegate = self

presentViewController(destinationVC, animated: true, completion: nil)

Check out the example project for examples of both methods, and be sure to check out the PresentationOption enum! For example, you could get a presentation very similar to the compose in Mail.app with something like:

ElegantPresentations.controller(..., options: [. PresentedHeight(view.frame.height - 40)])

Options

The factory method for creating the controller takes an option set, which is an array of PresentationOption. They are all implemented in the example project with easy toggles to try them all out.

enum PresentationOption {
    case NoDimmingView                      // Don't dim the presenting view controller
    case DismissOnDimmingViewTap            // Tapping outside the presented view controller dismisses it
    case PresentingViewKeepsSize            // Prevent the presenting view controller from shrinking back 
    case PresentedHeight(CGFloat)           // Give the presented view controller a fixed height
    case PresentedPercentHeight(Double)     // Give the presented view controller a percent height (of the presenting view controller)
}

TODO

  • [X] Adapt to rotation
  • [ ] Animate presenting view better when rotated

Contribute

I’m new to creating libraries, so if I can improve this in anyway please let me know! Open an issue, make a pull request, or reach out on twitter.

Latest podspec

{
    "name": "ElegantPresentations",
    "platforms": {
        "ios": "8.0"
    },
    "summary": "ElegantPresentations: present view controllers with style.",
    "requires_arc": true,
    "version": "2.0",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Kyle Bashour": "[email protected]"
    },
    "homepage": "https://github.com/kylebshr/ElegantPresentations",
    "source": {
        "git": "https://github.com/kylebshr/ElegantPresentations.git",
        "tag": "2.0"
    },
    "frameworks": "UIKit",
    "source_files": "ElegantPresentations/*.{swift}"
}

Pin It on Pinterest

Share This