美文网首页搬砖
iOS-星球沿椭圆轨迹旋转

iOS-星球沿椭圆轨迹旋转

作者: 一只搬运工的自我修养 | 来源:发表于2017-12-22 17:26 被阅读426次

先看效果:


QQ20171222-170814-HD.gif

什么?太模糊!
来一张高清无码

图片.png

背景旋转

    CABasicAnimation *animation =  [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    //默认是顺时针效果,若将fromValue和toValue的值互换,则为逆时针效果
    animation.fromValue = [NSNumber numberWithFloat:0.f];
    animation.toValue =  [NSNumber numberWithFloat: M_PI *2];
    animation.duration  = 200;
    animation.autoreverses = NO;
    animation.fillMode =kCAFillModeForwards;
    animation.repeatCount = MAXFLOAT; //如果这里想设置成一直自旋转,可以设置为MAXFLOAT,否则设置具体的数值则代表执行多少次
    [ self.bgImaegview.layer addAnimation:animation forKey:nil];

星星的闪烁

-(CABasicAnimation *)opacityForever_Animation:(float)time
{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];//必须写opacity才行。
    animation.fromValue = [NSNumber numberWithFloat:1.0f];
    animation.toValue = [NSNumber numberWithFloat:0.0f];
    animation.autoreverses = YES;
    animation.duration = time;
    animation.repeatCount = MAXFLOAT;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];///没有的话是均匀的动画。
    return animation;
}

轨迹动画

   CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        pathAnimation.calculationMode = kCAAnimationPaced;
        pathAnimation.fillMode = kCAFillModeForwards;
        pathAnimation.removedOnCompletion = NO;
        pathAnimation.repeatCount = CGFLOAT_MAX;
        pathAnimation.duration = 30.0;
        CGMutablePathRef ovalfromarc = CGPathCreateMutable();
        CGAffineTransform t2 = CGAffineTransformConcat(CGAffineTransformConcat(                                                                 CGAffineTransformMakeTranslation(-origin_x,-origin_y),                                                                             CGAffineTransformMakeScale(1, radiuscale)),                                                      CGAffineTransformMakeTranslation(origin_x, origin_y));
        CGPathAddArc(ovalfromarc, &t2, origin_x, origin_y, radiusX,beginAng,endAng, 0);
        pathAnimation.path = ovalfromarc;
        CGPathRelease(ovalfromarc);

绘制椭圆

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);
    UIBezierPath *arc = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(20+40, 25, SCREEN_WIDTH-40,SCREEN_WIDTH/2-50)];
    [COLOR(147.f, 151.f, 157.f,0.5f)  setStroke];
    [arc stroke];
    CGContextRestoreGState(context);

下面是demo地址
链接: https://pan.baidu.com/s/1bp4jHWr 密码: 5mt6

感谢作者:秋雨W
https://www.jianshu.com/p/d8cc02e7efa7

相关文章

  • iOS-星球沿椭圆轨迹旋转

    先看效果: 什么?太模糊!来一张高清无码 背景旋转 星星的闪烁 轨迹动画 绘制椭圆 下面是demo地址链接: ht...

  • svg实现沿椭圆轨迹旋转动画

    需求1.实现元素沿椭圆轨迹均匀旋转2.鼠标点击事件、移入暂停运动3.元素由远到近逐渐增大 旋转动画的实现思路:1....

  • iOS 控件沿椭圆旋转

    人生总是这么的无奈,有一个奇葩的UI给你提供奇葩的原型图,让你软件写出来效果。这就是我们苦逼的程序员。 项目需求:...

  • css3实现沿椭圆轨迹旋转动画

    需求1.实现元素沿椭圆轨迹均匀旋转2.鼠标点击事件、移入暂停运动3.元素由远到近逐渐增大 网上关于css3实现旋转...

  • css实现椭圆轨迹旋转

    X轴Y轴在一个矩形内移动 做斜线运动 设置动画延时 设置Y轴延时为动画时长的一半, 运动轨迹变成菱形 设置三次贝塞...

  • View动画ii(沿椭圆轨迹运动)

  • 图片沿轨迹旋转、缩放、透明。

    demo地址https://github.com/yinbowang/YBPhothFlyImageView.git

  • 沿轨迹行走

    校区:科学创想乐高机器人和平校区 时间:周日14:00——16:00 学员:宋雨璇 梁雨萱 任教老师:郑倩倩 教学...

  • 沿轨迹行走

    班级情况: 校区:科学创想乐高机器人和平校区 时间:周二17:00——19:00 学员:宋美萱 杜昊杨 任教老师:...

  • 3D变形(css3)transform

    rotateX() 就是沿着 x 立体旋转. 沿X轴旋转 沿Z轴旋转: 透视(perspective) persp...

网友评论

    本文标题:iOS-星球沿椭圆轨迹旋转

    本文链接:https://www.haomeiwen.com/subject/fjdxgxtx.html