美文网首页
水波纹动画

水波纹动画

作者: 又又轻 | 来源:发表于2016-10-10 18:28 被阅读99次

    CAShapeLayer *shaper = [CAShapeLayer layer];

    shaper.fillColor = [UIColor redColor].CGColor;

    [self.view.layer addSublayer:shaper];

    CADisplayLink *display = [CADisplayLink displayLinkWithTarget:self selector:@selector(currentWave)];

    [display addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];

    -(void)currentWave

    {

        CGMutablePathRef path = CGPathCreateMutable();

        CGPathMoveToPoint(path, NULL, 0, 100);

        CGFloat y = 0.f;

        /*水波纹动画  根据余旋公式*/

       for (CGFloat x = 0.f; x<=12; x++) {

            y = 2*sin(0.01*(23*x+11*y));

           CGPathAddLineToPoint(path, NULL, x, y);

       }

       CGPathAddLineToPoint(path, NULL, y, y);

       CGPathAddLineToPoint(path, NULL, 0, 0);

       CGPathCloseSubpath(path);

    }

    相关文章

      网友评论

          本文标题:水波纹动画

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