```
前提是有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];
}
```
网友评论