Wow, I worked on the same thing today. :) Check this out:
So, the view in which I draw the waves is initialized as:
_self_view = [[TDTWaveView alloc] initWithFrame:CGRectMake(-320, 174, 640, 200)];
Then in my view of [self animateWave]; I call [self animateWave]; once.
- (void)animateWave { [UIView animateWithDuration:.5 delay:0.0 options:UIViewAnimationOptionRepeat|UIViewAnimationOptionCurveLinear animations:^{ _self_view.transform = CGAffineTransformMakeTranslation(+_self_view.frame.size.width/2, 0); } completion:^(BOOL finished) { _self_view.transform = CGAffineTransformMakeTranslation(0, 0); }]; }
This gives the wave some linear motion that you may need.
As for the code for the wave, I will share the line.
self.yc = 30//The height of a crest. float w = 0;//starting x value. float y = rect.size.height; float width = rect.size.width; int cycles = 7;//number of waves self.x = width/cycles; CGContextRef context = UIGraphicsGetCurrentContext(); CGMutablePathRef path = CGPathCreateMutable(); CGContextSetLineWidth(context, .5); while (w <= width) { CGPathMoveToPoint(path, NULL, w,y/2); CGPathAddQuadCurveToPoint(path, NULL, w+self.x/4, y/2 - self.yc, w+self.x/2, y/2); CGPathAddQuadCurveToPoint(path, NULL, w+3*self.x/4, y/2 + self.yc, w+self.x, y/2); w+=self.x; } CGContextAddPath(context, path); CGContextDrawPath(context, kCGPathStroke);