Je dessine une couche d'onde par substitution procédé drawInContext:(CGContextRef)ctx
, étant donné que la ligne d'onde est sinusoïdale, je couper en segments par calculer la valeur de l'onde et les rejoindre dans CGMutablePathRef
CALayer drawRect anticrénelage n'a pas travaillé
Voici ce que je l'ai fait dans -(void)drawInContext:(CGContextRef)ctx
//join style
CGContextSetLineJoin(ctx, kCGLineJoinRound);
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetAllowsAntialiasing(ctx, true);
CGContextSetShouldAntialias(ctx, true);
CGContextSetFillColorWithColor(ctx, [UIColor themeColor].CGColor);
CGContextSetStrokeColorWithColor(ctx, [UIColor themeColor].CGColor);
CGContextSaveGState(ctx);
CGMutablePathRef mutablePath = CGPathCreateMutable();
CGPathMoveToPoint(mutablePath, NULL, 0, 0);
CGPathAddLineToPoint(mutablePath, NULL, 0, [self getSinPoint:0 WaveHeight:self.waveHeight]);
//Calculate the Sin funciton value to draw lines and join them into path
for (float i = 0; i <= self.bounds.size.width; i+= 1) {
NSInteger pointY = [self getSinPoint:i WaveHeight:self.waveHeight];
CGPathAddLineToPoint(mutablePath, NULL, i, pointY);
}
CGPathAddLineToPoint(mutablePath, NULL, self.bounds.size.width, 0);
CGPathCloseSubpath(mutablePath);
[[UIColor themeColor]set];
CGContextAddPath(ctx, mutablePath);
CGContextFillPath(ctx);
CGContextRestoreGState(ctx);
Peut-être en utilisant la méthode de péché pour calculer couper la ligne dans le boîtier trop de lignes bord flou, mais je ne comprends pas pourquoi il n'est pas encore assez lisse même si je dessine chaque ligne à 0,5 dp. Je peux l'accepter en basse performance, mais pas en dents de scie. – pf0214