OC动画:CAAnimationGroup

余生长醉 提交于 2020-04-04 20:35:25

 

 

        //贝塞尔曲线路径
        UIBezierPath *movePath = [UIBezierPath bezierPath];
         [movePath moveToPoint:CGPointMake(10.0, 10.0)];
         [movePath addQuadCurveToPoint:CGPointMake(100, 300) controlPoint:CGPointMake(300, 100)];
    
        //以下必须导入QuartzCore包
       //关键帧动画(位置)
         CAKeyframeAnimation * posAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
         posAnim.path = movePath.CGPath;
         posAnim.removedOnCompletion = YES;
    
         //缩放动画
         CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
         scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
         scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.5, 0.5, 0.1)];

        scaleAnim.removedOnCompletion = YES;
    
         //透明动画
         CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
         opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
         opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
         opacityAnim.removedOnCompletion = YES;
    
         //动画组
         CAAnimationGroup *animGroup = [CAAnimationGroup animation];
         animGroup.animations = [NSArray arrayWithObjects:posAnim, scaleAnim, opacityAnim, nil];
         animGroup.duration = 1;
    
         [redView.layer addAnimation:animGroup forKey:nil];

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!