Swiftpack.co - Package - rishi420/Bonsai


Version License Platform

🌲 Bonsai makes iOS View Controller present modally in any size and any position with cool transition animation.



  • Makes view controller appear as
    • ☑ Popup alert (no dismiss on tap outside)
    • ☑ Notification alert (auto dismiss after delay)
    • ☑ Side menu (drawer)
  • Transition animation
    • ☑ Slide In from left, right, top and bottom
    • ☑ Bubble pop from an initial frame or a view
  • Blur effect on background
    • ☑ light, dark, regular, prominent
  • Supports Storyboard and Code
  • Supports landscape and portrait orientation
  • Created with Swift compatible with Objective-C
  • Preserves Safe Area and Auto Layout constraints

Installation with CocoaPods

BonsaiController is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'BonsaiController'

Install Manually

Drag the ~/BonsaiController directory anywhere in your project.

How to use

import BonsaiController

Add (copy paste) BonsaiControllerDelegate extension to your view controller

extension YourViewController: BonsaiControllerDelegate {
    // return the frame of your Bonsai View Controller
    func frameOfPresentedView(in containerViewFrame: CGRect) -> CGRect {
        return CGRect(origin: CGPoint(x: 0, y: containerViewFrame.height / 4), size: CGSize(width: containerViewFrame.width, height: containerViewFrame.height / (4/3)))
    // return a Bonsai Controller with SlideIn or Bubble transition animator
    func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
        /// With Background Color ///
        // Slide animation from .left, .right, .top, .bottom
        return BonsaiController(fromDirection: .bottom, backgroundColor: UIColor(white: 0, alpha: 0.5), presentedViewController: presented, delegate: self)
        // or Bubble animation initiated from a view
        //return BonsaiController(fromView: yourOriginView, backgroundColor: UIColor(white: 0, alpha: 0.5), presentedViewController: presented, delegate: self)
        /// With Blur Style ///
        // Slide animation from .left, .right, .top, .bottom
        //return BonsaiController(fromDirection: .bottom, blurEffectStyle: .light, presentedViewController: presented, delegate: self)
        // or Bubble animation initiated from a view
        //return BonsaiController(fromView: yourOriginView, blurEffectStyle: .dark,  presentedViewController: presented, delegate: self)

How to present the view controller

From Code:

let smallVC = YourViewController() // instantiateViewController(withIdentifier:)
smallVC.transitioningDelegate = self
smallVC.modalPresentationStyle = .custom
present(smallVC, animated: true, completion: nil)

From Storyboard:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if segue.destination is YourViewController {
        segue.destination.transitioningDelegate = self
        segue.destination.modalPresentationStyle = .custom


Auto dismiss after delay

let bonsaiController = BonsaiController(...
bonsaiController.perform(#selector(bonsaiController.dismiss), with: nil, afterDelay: 2)

Customizable properties (Default values)

bonsaiController.springWithDamping = 0.8
bonsaiController.duration = 0.4
bonsaiController.isDisabledTapOutside = false
bonsaiController.isDisabledDismissAnimation = false
bonsaiController.dismissDirection = nil // Reverse direction. Availabel only for slide in transition.

Custom transition animation

If you want to create your own transition animation, implement this protocol in your viewController

extension YourViewController: UIViewControllerTransitioningDelegate {

    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        // Your presentation animation hear

    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        // Your dismiss animation here

Usage In Objective-C

#import "YourModuleName-Swift.h"  // only if project created in swift

@import BonsaiController;

Add (copy paste) BonsaiControllerDelegate extension to your view controller

// MARK:- Bonsai Controller Delegate
- (CGRect)frameOfPresentedViewIn:(CGRect)containerViewFrame {

    return CGRectMake(0, containerViewFrame.size.height / 4, containerViewFrame.size.width, containerViewFrame.size.height / (4.0 / 3.0));

- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source {

    // Slide animation from .left, .right, .top, .bottom
    //return [[BonsaiController alloc] initFromDirection:DirectionBottom blurEffectStyle:UIBlurEffectStyleLight presentedViewController:presented delegate:self];

    // or Bubble animation initiated from a view
    return [[BonsaiController alloc] initFromView:self.exampleButton blurEffectStyle:UIBlurEffectStyleDark presentedViewController:presented delegate:self];

How to present the view controller(obj-c)

From Code:

SmallViewController *smallVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SmallVC"];
smallVC.transitioningDelegate = self;
smallVC.modalPresentationStyle = UIModalPresentationCustom;
[self presentViewController:smallVC animated:true completion:nil];

From Storyboard:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.destinationViewController isKindOfClass:SmallViewController.class]) {
        segue.destinationViewController.transitioningDelegate = self;
        segue.destinationViewController.modalPresentationStyle = UIModalPresentationCustom;


An example project is included with this repo. To run the example project, clone the repo, and run pod install from the Example directory first.

Minimum Requirements

  • Xcode 10.2 with swift5 (check previous releases and pod versions for older xcode)
  • iOS 9.3

Your input is welcome!

If you have any suggestions, please get in touch with us. If you need help or found a bug, please open an issue. If you have a new transition animation or want to contribute, please submit a pull request.

Let us know!

If you like BonsaiController, give it a ★ at the top right of this page. Using BonsaiController in your app? Send us a link to your app in the app store!


Thank You

A special thank you to everyone that has contributed to this library to make it better. Your support is appreciated!


Developer: Warif Akhand Rishi, rishi420@gmail.com Designer: Takmila Tasmim Mim, mim.tasmim93@gmail.com


BonsaiController is available under the MIT license. See the LICENSE file for more info.

Support Us


Stars: 57


Used By

Total: 0






Swift 5 -

swift 4.2 -

This is last version supporting swift4.2 with xcode 10.2