HWModalTransition 1.0.1

HWModalTransition 1.0.1

wanghouwen维护。



  • 作者:
  • wanghouwen

HWModalTransition

CI Status Version License Platform

示例

要运行示例项目,请先克隆仓库,然后从 Example 目录运行 pod install

如何让一个 UIViewController 实现自定义转场效果

步骤 1

vc.modalPresentationStyle = UIModalPresentationCustom

步骤 2

vc.transitioningDelegate = HWModalTransition 对象

步骤 3

实例化HWModalTransition对象

// present转场对象
present = [HWTransitionAnimator animatorWithDuration:0.15 animate:^(HWModalTransitioningContext *context, HWCompleteBlock complete) {

  // 可根据需求对某些view添加手势
  [context.containerView addGestureRecognizer:[UITapGestureRecognizer gestureRecognizerWithHandler:^(__kindof UIGestureRecognizer *ges) {
      [context.presentedVC dismissViewControllerAnimated:YES completion:nil];
      }]];


  // 自定义你的动画效果
  context.toVC.view.frame = CGRectMake(0, screenSize.height, screenSize.width, screenSize.height * 0.5f);
  [UIView animateWithDuration:0.15 delay:0.0 usingSpringWithDamping:10 initialSpringVelocity:10 options:UIViewAnimationOptionCurveEaseInOut animations:^{
  
    context.toVC.view.top = screenSize.height * 0.5f;
    
    } completion:^(BOOL finished) {
      complete(); // 动画结束一定要调用这个block块,否则转场未完成下一次无法继续转场
    }];
}];

// dismiss转场对象
dismiss = [HWTransitionAnimator animatorWithDuration:0.15 animate:^(HWModalTransitioningContext *context, HWCompleteBlock complete) {

  // 自定义你的动画效果
  [UIView animateWithDuration:0.15 delay:0.0 usingSpringWithDamping:10 initialSpringVelocity:10 options:UIViewAnimationOptionCurveEaseInOut animations:^{
  
      context.fromVC.view.top = screenSize.height;
      
    } completion:^(BOOL finished) {
      complete(); // 动画结束一定要调用这个block块,否则转场未完成下一次无法继续转场
    }];
}];

HWModalTransition object = [HWModalTransition transitionWithPresentAnimator:present dismissAnimator:dismiss];

如何支持手势交互?

在合适的视图中添加手势,在手势处理方法中调用以下方法来更新转场动画进度

- (void)updateTransitionWithPercentComplete:(CGFloat)percent forOperation:(HWModalTransitionOperation)operation
 status:(HWTransitionStatus)status;

注意:1、对于一个已经处于percent状态的vc,在手势交互时以上方法operation参数应该传HWModalTransitionOperationDismiss,因为你不能再一次设置percent这个vc; dismiss 状态也是同理;2、以上方法如果status状态传 HWTransitionStatusFinish 或 HWTransitionStatusCancel 时,percent参数将被忽略。

需求

安装

HWModalTransition可以通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中

pod 'HWModalTransition'

作者

王厚文,[email protected]

许可协议

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