基于POP动画实现从界面底部弹出筛选框或者分享框的减速回弹效果
项目实例如下: 动画效果为弹窗从底部弹出,并产生回弹动画效果
主要动画实现逻辑代码为:(先导入pop.h头文件,pop引擎可github下载)
弹出时:
// 上滑回弹
POPSpringAnimation *anSpring = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY];
anSpring.toValue = @(self.choiceView.center.y-300*ScreenHeightRate);
anSpring.beginTime = CACurrentMediaTime()+0.2f;
anSpring.springBounciness = 15.0f;
anSpring.springSpeed = 12;
[self.choiceView pop_addAnimation:anSpring forKey:@"position"];
// 执行动画 改变关闭按钮透明度
POPBasicAnimation *alpha = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
alpha.toValue = @(1.f);
alpha.duration = 0.7f;
alpha.beginTime = CACurrentMediaTime() + 0.8f;
[self.closeBtn pop_addAnimation:alpha forKey:nil];
消失时(由于需要保持生命周期和上次选项的状态,没有removeFromSubview):
- (void)viewGlide{
// 下滑退出
[UIView animateWithDuration:0.3f animations:^{
self.blackView.alpha = 0.f;
self.closeBtn.alpha = 0.f;
self.choiceView.transform = CGAffineTransformMakeTranslation(0, 300*ScreenHeightRate);
} completion:^(BOOL finished) {
if (finished) {
self.choiceView.transform = CGAffineTransformIdentity; // 恢复原始状态
self.choiceView.frame = CGRectMake(12, self.height, self.width-24, 300*ScreenHeightRate);
self.alpha = 0;
}
}];
}