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);
}
网友评论