美文网首页
CATransition底部弹出与移除

CATransition底部弹出与移除

作者: Younggg | 来源:发表于2021-07-26 16:47 被阅读0次

    ```

    前提是有view有高度

    - (void)addAnimationForBottomSheet {

        CGFloat bgViewHeight = (self.actions.count - 1) * buttonHeightForBottomActionSheet + buttonHeightForActionSheet +8 + getBottomAreaHeight();

        [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {

            make.height.mas_equalTo(bgViewHeight);

        }];

        CATransition *animation = [CATransition animation];

        animation.duration = kBottomAnimationDuration;//设置动画时间

        animation.type = kCATransitionPush;//设置动画类型

        animation.subtype = kCATransitionFromTop; //动画方向

        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

        [self.bgView.layer addAnimation:animation forKey:@"pushAnimation"];

    }

    - (void)removeAnimationForBottomSheet {

        CGFloat bgViewHeight = (self.actions.count - 1) * buttonHeightForBottomActionSheet + buttonHeightForActionSheet +8 + getBottomAreaHeight();

        [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {

            make.bottom.mas_equalTo(self.view.mas_bottom).offset(bgViewHeight);

          }];

        [self.view layoutIfNeeded];

        CATransition *animation = [CATransition animation];

        animation.duration = kBottomAnimationDuration;//设置动画时间

        animation.type = kCATransitionPush;//设置动画类型

        animation.subtype = kCATransitionFromBottom; //动画方向

        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

        [self.bgView.layer addAnimation:animation forKey:nil];

    }

    ```

    相关文章

      网友评论

          本文标题:CATransition底部弹出与移除

          本文链接:https://www.haomeiwen.com/subject/bedgmltx.html