Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

期望可以支持帧动画,建议将[alert]或[sheet]布局的容器视图[containerView]返回给外界 #155

Open
szmichaelyb opened this issue Sep 5, 2021 · 0 comments

Comments

@szmichaelyb
Copy link

szmichaelyb commented Sep 5, 2021

为便于支持帧动画,建议将布局弹窗或者sheet的容器视图[containerView]返回给外界

再做具体业务的时候,发现使用[LeeOpenAnimationConfig]配置自定义动画的时候,除了默认动画之外,还可以使用block动画,但还是略显样式单一,不能实现实际业务期望的动画,希望能支持帧动画。

1. 通过验证发现,只要将[containerView]返回给外界是可以实现帧动画的。

下面我描述一下帧动画的实现办法,仅为简单实现方式,希望作者能支持,采纳方案,或者实现更完善的解决方案,谢谢~

  • LEEAlertHelper.h文件

    typedef LEEBaseConfigModel * _Nonnull (^LEEConfigToBlockAndBlock)(void(^)(UIView *containerView,void(^animatingBlock)(void),void(^animatedBlock)(void)));
  • LEEAlert.h文件

    @property (nonatomic, copy, readonly) LEEConfigToBlockAndBlock LeeOpenAnimationConfig;
  • LEEAlert.m文件

    @property (nonatomic, copy) void(^modelOpenAnimationConfigBlock)(UIView *containerView, void(^animatingBlock)(void), void(^animatedBlock)(void));
    
    
    - (LEEConfigToBlockAndBlock)LeeOpenKeyAnimationConfig
    {
          return ^(void(^block)(UIView *containerView,void(^animatingBlock)(void),void(^animatedBlock)(void))){
               
                self.modelOpenAnimationConfigBlock = block;
                 
                return self;
          };
    }
    
    /// 在 showAnimationsWithCompletionBlock 方法中
    - (void)showAnimationsWithCompletionBlock:(void (^)(void))completionBlock
    {
      	/// 前面代码省略
      	/// 帧动画相关
      	if (self.config.modelOpenAnimationConfigBlock) self.config.modelOpenAnimationConfigBlock(self.containerView,^{
         
           if (!weakSelf) return ;
           
           if (weakSelf.config.modelBackgroundStyle == LEEBackgroundStyleTranslucent) {
               
               weakSelf.view.backgroundColor = [weakSelf.view.backgroundColor colorWithAlphaComponent:weakSelf.config.modelBackgroundStyleColorAlpha];
               
           } else if (weakSelf.config.modelBackgroundStyle == LEEBackgroundStyleBlur) {
               
               weakSelf.backgroundVisualEffectView.effect = [UIBlurEffect effectWithStyle:weakSelf.config.modelBackgroundBlurEffectStyle];
           }
           
           CGRect containerFrame = weakSelf.containerView.frame;
           
           containerFrame.origin.x = (viewWidth - containerFrame.size.width) * 0.5f;
           
           containerFrame.origin.y = (viewHeight - containerFrame.size.height) * 0.5f;
           
           weakSelf.containerView.frame = containerFrame;
           
           weakSelf.containerView.alpha = 1.0f;
           
           weakSelf.containerView.transform = CGAffineTransformIdentity;
           
       }, ^{
           
           if (!weakSelf) return ;
           
           weakSelf.isShowing = NO;
           
           [weakSelf.view setUserInteractionEnabled:YES];
           
           if (weakSelf.openFinishBlock) weakSelf.openFinishBlock();
           
           if (completionBlock) completionBlock();
       });
    }
    
    

2. 外界帧动画代码实现(举例)

  • 以前只能使用Block动画

    .LeeOpenAnimationConfig(^(void (^animatingBlock)(void), void (^animatedBlock)(void)) {
        [UIView animateWithDuration:1.0f delay:0 usingSpringWithDamping:0.4 initialSpringVelocity:1.0f options:UIViewAnimationOptionAllowUserInteraction animations:^{
          	animatingBlock(); // 调用动画中Block
        } completion:^(BOOL finished) {
          	animatedBlock();  // 调用动画结束Block
        }];
    })
  • 现在可以使用帧动画

    /// 帧动画代码
    - (void)animationForView:(UIView*)view
    {
        NSMutableArray * values = [NSMutableArray array];
        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.7, 0.7, 1.0)]];
        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1, 1.1, 1.0)]];
        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.95, 0.95, 1.0)]];
        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.02, 1.02, 1.0)]];
        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
        CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
        animation.duration = 0.5f;
        animation.removedOnCompletion = YES;
        animation.fillMode = kCAFillModeForwards;
        animation.values = values;
        [view.layer addAnimation:animation forKey:nil];
    }
    
    /// 弹窗帧动画代码实现(改造后)
    @weakify(self)
    .LeeOpenAnimationConfig(^(UIView *containerView, void(^animatingBlock)(void), void(^animatedBlock)(void)) {
          @strongify(self)
          if(animatingBlock) animatingBlock(); // 调用动画中Block
          [self animationForView:containerView];
          if(animatedBlock) animatedBlock();   // 调用动画结束Block
    })
@szmichaelyb szmichaelyb changed the title 为便于支持帧动画,建议将布局弹窗或者sheet的容器视图[containerView]返回给外界 期望可以支持帧动画,建议将[alert]或[sheet]布局的容器视图[containerView]返回给外界 Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant