π² 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
BonsaiController is available through CocoaPods. To install it, simply add the following line to your Podfile:
use_frameworks!
pod 'BonsaiController'
Drag the ~/BonsaiController
directory anywhere in your project.
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)
}
}
let smallVC = YourViewController() // instantiateViewController(withIdentifier:)
smallVC.transitioningDelegate = self
smallVC.modalPresentationStyle = .custom
present(smallVC, animated: true, completion: nil)
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.destination is YourViewController {
segue.destination.transitioningDelegate = self
segue.destination.modalPresentationStyle = .custom
}
}
let bonsaiController = BonsaiController(...
bonsaiController.perform(#selector(bonsaiController.dismiss), with: nil, afterDelay: 2)
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.
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
}
}
#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];
}
SmallViewController *smallVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SmallVC"];
smallVC.transitioningDelegate = self;
smallVC.modalPresentationStyle = UIModalPresentationCustom;
[self presentViewController:smallVC animated:true completion:nil];
- (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.
- Xcode 10.2 with swift5 (check previous releases and pod versions for older xcode)
- iOS 9.3
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.
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!
- Jelly - https://github.com/SebastianBoldt/Jelly
- PresentHalfModal - https://github.com/khuong291/PresentHalfModal
- SideMenu - https://github.com/jonkykong/SideMenu
- TransitionTreasury - https://github.com/DianQK/TransitionTreasury
- Transition - https://github.com/Touchwonders/Transition
- StarWars.iOS - https://github.com/Yalantis/StarWars.iOS
- Hero - https://github.com/HeroTransitions/Hero
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.