BonsaiController 7.0.2

BonsaiController 7.0.2

Warif Akhand Rishi维护。



  • 作者:
  • Warif Akhand Rishi

Bonsai

Version License Platform

🌲 Bonsai 让 iOS 视图控制器可以以任何大小和位置弹窗,带有酷炫的过渡动画。

Bonsai

特点

  • 可以将视图控制器显示为
    • 弹出警告(点击外部无关闭)
    • 通知警告(延迟自动关闭)
    • 侧边菜单(抽屉)
  • 过渡动画
    • 从左侧、右侧、顶部和底部滑动进入
    • 从初始帧或视图弹出气泡
  • 背景模糊效果
    • 亮色、暗色、普通、突出
  • 支持 Storyboard 和 Code
  • 支持横屏和竖屏方向
  • 用 Swift 创建,与 Objective-C 兼容
  • 保留安全区域和 Autolayout 约束

使用 CocoaPods 安装

BonsaiController 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中:

use_frameworks!
pod 'BonsaiController'

手动安装

~/BonsaiController 文件夹拖到您的项目中的任何位置。

如何使用

import BonsaiController

BonsaiControllerDelegate 扩展添加到你的视图控制器中(复制粘贴)

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.

自定义过渡动画

如果您想要创建自己的过渡动画,请在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
    }
}

Objective-C中的用法

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

@import BonsaiController;

BonsaiControllerDelegate 扩展添加到你的视图控制器中(复制粘贴)

// 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];
}

如何展示viewController(obj-c)

从代码中

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;
    }
}

示例

与此代码库一起包含了一个示例项目。要运行示例项目,首先克隆该代码库,然后从Example目录运行pod install

最低要求

  • 使用 Xcode 10.2 和 Swift 5(检查以前的发布版本和 pod 版本以了解较旧的 Xcode 版本)
  • iOS 9.3

欢迎您的反馈!

如果您有任何建议,请与联系。
如果您需要帮助或发现了虫子,请创建一个问题。
如果您有新的过渡动画或希望贡献,请提交一个 pull request。

告诉我们!

如果您喜欢 BonsaiController,请在此页面的右上角给予它一个 ★ 星。
在您的应用中使用 BonsaiController?请通过 App Store 发送您应用链接。

致谢

感谢

特别感谢为这个库做出贡献的每一个人,使它变得更好。感谢您的支持!

作者

开发者:Warif Akhand Rishi,[email protected]
设计师:Takmila Tasmim Mim,[email protected]

授权许可

BonsaiController 可在 MIT 许可下使用。有关更多信息,请参阅 LICENSE 文件。

支持我们

Buy Me A Coffee