CATransition底部弹出与移除

2021-07-26  本文已影响0人  Younggg

```

前提是有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];

}

```

上一篇 下一篇

猜你喜欢

热点阅读