夜梦程序,日实现(下载动画)

来源:互联网 发布:北京大土豆 知乎 编辑:程序博客网 时间:2024/05/08 09:58

          最近加班太忙了,晚上经常加班,所以晚上会经常梦到在写代码,昨晚在睡觉的时候梦见我去一个商场买衣服,一个售货员用ipad 给我推荐他们的衣服,用的那个app 很精致,一开始就是一个动画,刚好前几天在我们的项目中也有类似的功能,但是没有这个app 的  动画好看,当时我就很兴奋,然后一大早起来原来是做梦,但是梦里面的动画也不难实现,今天就抽空写了下。也用到了第三方的一个类。主要动画就是一个下载进度条,然后有文件从源文件夹飞到目的文件夹, 具体主要代码是:

- (void)changeProgressValue{    float progressValue = progressView.progress;        progressValue       += 0.01f;    if (progressValue > 1)    {        progressValue = 0;    }        if ((int)(progressValue * 100)%3==0) {        [self tranAction];    }    [progressValueLabel setText:[NSString stringWithFormat:@"%.0f%%", (progressValue * 100)]];    [progressView setProgress:progressValue];} - (void)tranAction{        CGPoint fromPoint = imageView.center;        //路径曲线    UIBezierPath *movePath = [UIBezierPath bezierPath];    [movePath moveToPoint:fromPoint];    CGPoint toPoint = CGPointMake(300, 570);    [movePath addQuadCurveToPoint:toPoint                     controlPoint:CGPointMake(300,0)];        //关键帧    CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];    moveAnim.path = movePath.CGPath;    moveAnim.removedOnCompletion = YES;        //旋转变化    CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];    scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];    //x,y轴缩小到0.1,Z 轴不变    scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.3, 0.3, 1.0)];    scaleAnim.removedOnCompletion = YES;        //透明度变化    CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];    opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];    opacityAnim.toValue = [NSNumber numberWithFloat:0.4];    opacityAnim.removedOnCompletion = YES;        //关键帧,旋转,透明度组合起来执行    CAAnimationGroup *animGroup = [CAAnimationGroup animation];    animGroup.animations = [NSArray arrayWithObjects:moveAnim, scaleAnim,opacityAnim, nil];    animGroup.duration = 1;    [imageView.layer addAnimation:animGroup forKey:nil];    }

效果图:



 源代码下载地址

原创粉丝点击