ElegantPresentations 2.0

ElegantPresentations 2.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Oct 2016
SPMSupports SPM

Maintained by Kyle Bashour.



  • By
  • Kyle Bashour

ElegantPresentations

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!

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.