YLTransition 1.1.1

YLTransition 1.1.1

TaPeJu 维护。



  • 命运

YLTransition

YLTransition 是一个用于动画、非交互式和交互式 ViewController Present 和 Dismiss 的库

使用

#import <YLTransition/YLTransition.h>

PresentedViewController *presentedVc = [[PresentedViewController alloc] init];
YLModalTransitionManager *animator = [[YLModalTransitionManager alloc] initWithPresentedViewController:presentedVc presentingViewController:self];
animator.animationType = YLAnimationTypeTransformCenter;
[self presentViewController:presentedVc animated:YES completion:nil];

在 PresentedViewController 中需要加入以下代码,用于自适应弹出控制器的宽高

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.whiteColor;
    [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
}


- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
    [super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator];
    [self updatePreferredContentSizeWithTraitCollection:newCollection];
}

- (void)updatePreferredContentSizeWithTraitCollection:(UITraitCollection *)traitCollection {
    self.preferredContentSize = CGSizeMake(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height);
}

对于需要根据网络返回数据确定大小的,只需要在获取到网络数据后重新设置 self.preferredContentSize 即可自适应大小

交互式过渡

关闭

只需一行代码即可实现交互式关闭

animator.dragable = YES;

如果您 present 出来的 controller 上有 scrollView,并且想要支持拖动关闭,也只需一行代码,内部已处理所有事情

[animator setContentScrollView:presentedVc.scrollview];

呈现

  __weak __typeof(self)weakSelf = self;
// YLDirectionAbstractPanGesTureRecognizer 该手势只接受向特定方向滑动的事件 
// YLLeftPanGesTureRecognizer 为 YLDirectionAbstractPanGesTureRecognizer 子类 只接受向左滑动的事件
  YLDirectionAbstractPanGesTureRecognizer *interactiveTransitionRecognizer = [[YLLeftPanGesTureRecognizer alloc] init];
  __weak __typeof(interactiveTransitionRecognizer)weakInteractive = interactiveTransitionRecognizer;

  interactiveTransitionRecognizer.beginBlock = ^{
     PresentedViewController *vc = [[RightViewController alloc] init];
     YLModalTransitionManager *animator = [[YLModalTransitionManager alloc] initWithPresentedViewController:vc presentingViewController:weakSelf];
     animator.presentGesture = weakInteractive;
     animator.viewAlignment = YLAlignment_Right;
     animator.animationType = YLAnimationTypeTranslation;
     animator.dragable = YES;
     [weakSelf presentViewController:vc animated:YES completion:nil];
  };

  [self.view addGestureRecognizer:interactiveTransitionRecognizer];

自定义

动画可以通过各种设置来配置

  • 半径
  • 矩形角落
  • 阻尼
  • 持续时间
  • 动画类型
  • 缩放比例
  • 展示手势
  • 可拖动
  • 视图对齐
  • 视图外边距
  • 自定义动画器

自定义动画

当YLTransition内部特效无法满足您的个性化需求时,可以使用customAnimator属性来实现自定义动画。该属性继承自YLAbstractAnimator,您只需实现- (void)animateTransition:(id)transitionContext方法,即可实现自定义动画。只要设置viewAlignment,YLTransition同样可以提供interactive transition手势驱动支持,您无需额外编写代码,具体可见demo。

		CustomViewController *presentedVc = [[CustomViewController alloc] init];
    YLModalTransitionManager *manager = [[YLModalTransitionManager alloc] 	  initWithPresentedViewController:presentedVc presentingViewController:self];
    CustomAnimator *animator =  [[CustomAnimator alloc] init];
    manager.customAnimator = animator;
    manager.dragable = YES;
    manager.radius = 13;
    manager.viewAlignment = YLAlignment_Top;
    manager.viewEdgeInsets = UIEdgeInsetsMake(20, 20, 20, 20);
    [self presentViewController:presentedVc animated:YES completion:nil];

安装

  • 使用CocoaPods

    pod "YLTransition"
  • 将YLTransition文件夹放入您的项目即可

作者

[email protected]

许可

YLTransition遵守MIT许可。更多信息请参阅LICENSE文件。