iOS动画——回弹动画实例(pop动画)

来源:互联网 发布:杭州比较好的美工培训 编辑:程序博客网 时间:2024/05/12 13:37


     


     基于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;        }                   }];}







0 0
原创粉丝点击