代码库> 视图动画> 太阳系太阳、地球、月亮自转公转动画
太阳系太阳、地球、月亮自转公转动画
关注
查看次数:7234 下载次数:572
上传时间:2017-05-08 大小:3 KB
一个自己写着玩的太阳系中太阳、地球和月亮自转、公转关系动画效果,另外还添加了一个下雪、流星等动画效果。
其中地球自转主要使用的代码:
animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//默认是顺时针效果,若将fromValue和toValue的值互换,则为逆时针效果
animation.fromValue = [NSNumber numberWithFloat:0.f];
animation.toValue = [NSNumber numberWithFloat: M_PI *2];

太阳系公转主要使用的代码:
CGMutablePathRef path1 = CGPathCreateMutable();
CGPathAddArc(path1, NULL, x, y, radius, 0,M_PI * 2, 0);
revolutionAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
revolutionAnimation.path = path1;
CGPathRelease(path1);

流星弧线运动动画效果代码:
_controlPoint = CGPointMake(screen_width/2, 100);
_endPoint = CGPointMake(screen_width+20, 80);

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, _meteor.center.x, _meteor.center.y);
CGPathAddQuadCurveToPoint(path, NULL, _controlPoint.x, _controlPoint.y, _endPoint.x, _endPoint.y);
CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.delegate = self;
animation.duration = 1.5;
animation.fillMode = kCAFillModeForwards;
animation.repeatCount = 2;
animation.path = path;
animation.removedOnCompletion = NO;
CGPathRelease(path);
[_meteor.layer addAnimation:animation forKey:@"meteor"];
收藏
我来说两句
发表评论
您还没有登录!请登录注册
所有评论(0
提示
sina weixin mail 回到顶部