Wow, j'ai travaillé exactement la même chose aujourd'hui. :) Vérifiez ceci:
donc le point de vue où je dessine mes vagues, est initialisés comme:
_self_view = [[TDTWaveView alloc] initWithFrame:CGRectMake(-320, 174, 640, 200)];
Puis dans mon viewDidLoad, j'appelle [self animateWave];
une fois.
- (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);
}];
}
Cela donne à l'onde une sorte de mouvement linéaire que vous pourriez souhaiter.
En ce qui concerne le code de la vague, je vais partager le dessin.
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);
C'est super! C'est presque ce que je cherche. Le seul problème que je vois quand j'ai essayé c'est l'animation de la vue n'est pas vraiment continue. Des idées? – Brian
J'ai laissé certaines petites choses pour que vous vous entraîniez exprès:/ – JohnVanDijk
Merci pour l'aide! – Brian