アプリでは、曲線のUIBezierPathをMKOverlayPathViewクラスで描き、飛行ルートを表示します。これは私が使用していたコードです:これはうまく機能していますが、私だけではなく、塗りつぶしの色のそのパスに沿ってグラデーションを描きたいと思い湾曲したUIBezierPathに沿ってグラデーションを描く
- (UIBezierPath *)pathForOverlayForMapRect:(MKMapRect)mapRect { ... bla bla bla ... UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:s]; [path addQuadCurveToPoint:e controlPoint:cp1]; [path addLineToPoint:e2]; [path addQuadCurveToPoint:s2 controlPoint:cp2]; [path closePath]; return path; }
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context{
self.mapRect = mapRect;
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
CGContextSetLineWidth(context, mapRect.size.height/700);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextAddPath(context, [self pathForOverlayForMapRect:mapRect].CGPath);
[self updateTouchablePathForMapRect:mapRect];
CGContextDrawPath(context, kCGPathFillStroke);
}
。そして、これは非常に扱いにくくなってきています。
私はCGContextDrawLinearGradient()を実験しましたが、まだ役に立たなかったことがあります。
この回答は完璧です!どうもありがとうございました。 'CGContextReplacePathWithStrokedPath()'を削除しました。私のパスはグラデーションで塗りつぶされ、輪郭線だけではありません。 – freshking
'CGContextReplacePathWithStrokedPath'は、パスの代わりにパス(質問単位)をグラントしたい場合に便利です。 – neilco
私が 'CGContextReplacePathWithStrokedPath'で得ていた問題は、グラデーションがパス自体にのみ適用されていて、それを塗りつぶさなかったことでした。塗りの代わりにストローク。それとも、何か間違ったことがありましたか? – freshking