Di seguito ho un'immagine allegata, voglio ottenere l'animazione seguente. Ho provato l'animazione ad onda d'acqua ma non so come controllare l'animazione come sopra.Animate CAShapeLayer con animazione ad onda
Ho CAShapeLayer
in cui devo realizzare questa animazione.
codice Init
UIBezierPath *leftPath = [UIBezierPath bezierPath];
// Set the starting point of the shape.
[leftPath moveToPoint:CGPointMake(0,self.bounds.size.height/2)];
// Draw the lines.
[leftPath addLineToPoint:CGPointMake(0,self.bounds.size.height/2)];
[leftPath addLineToPoint:CGPointMake(self.bounds.size.width,self.bounds.size.height/2)];
leftLayer.path = leftPath.CGPath;
leftLayer.strokeColor = [[UIColor whiteColor] CGColor];
leftLayer.fillColor = nil;
leftLayer.borderWidth = 3.0f;
leftLayer.lineCap = kCALineCapRound;
leftLayer.lineJoin = kCALineJoinRound;
leftLayer.borderColor=[UIColor blackColor].CGColor;
[self.layer addSublayer:leftLayer];
Codice Animazione
-(void)animateCureve{
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
pathAnimation.duration = 3.5;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pathAnimation.fromValue = (id)leftLayer.path;
pathAnimation.toValue = (id)[self wavePath].CGPath;
pathAnimation.removedOnCompletion=NO;
[leftLayer addAnimation:pathAnimation forKey:@"path"];
}
The Path Curve
- (UIBezierPath *)wavePath {
//set start and end accordingly
UIBezierPath *startPath = [UIBezierPath bezierPath];
[startPath moveToPoint:CGPointMake(0, self.bounds.size.height/2)];
[startPath addCurveToPoint:CGPointMake(self.bounds.size.width, self.bounds.size.height/2) controlPoint1:CGPointMake(50, self.bounds.size.height/2+0) controlPoint2:CGPointMake(self.bounds.size.width/2, 20) ];
return startPath;
}
ho eedited .plz check.I dà un'onda continua, con NSTimer – Mukesh
hey @ZevEisenberg Ho modificato il codice, può u si prega di controllare – Mukesh