J'utilise Quartz-2D pour iPhone pour afficher un itinéraire sur une carte. L'itinéraire est coloré en fonction de la température. Parce que certaines rues sont colorées en jaune, j'utilise une ligne noire légèrement plus épaisse sous la ligne de route pour créer un effet de bordure, de sorte que les parties jaunes de la route sont spottables sur les rues jaunes. Mais, même si la ligne noire est aussi épaisse que la ligne de route, tout le parcours ressemble à un ver (très moche). Je pensais que c'était parce que je dessinais des lignes du waypoint au waypoint, utilisant plutôt le dernier waypoint comme point de départ suivant. Ainsi, s'il manque quelques waypoints, l'itinéraire n'aura toujours pas de coupures.dessin quartz iphone 2 lignes sur le dessus de l'autre provoque un effet de vis sans fin
Que dois-je faire pour afficher les deux lignes sans un effet de ver?
-(void) drawRect:(CGRect) rect
{
CSRouteAnnotation* routeAnnotation = (CSRouteAnnotation*)self.routeView.annotation;
// only draw our lines if we're not int he moddie of a transition and we
// acutally have some points to draw.
if(!self.hidden && nil != routeAnnotation.points && routeAnnotation.points.count > 0)
{
CGContextRef context = UIGraphicsGetCurrentContext();
Waypoint* fromWaypoint = [[Waypoint alloc] initWithDictionary:[routeAnnotation.points objectAtIndex:0]];
Waypoint* toWaypoint;
for(int idx = 1; idx < routeAnnotation.points.count; idx++)
{
toWaypoint = [[Waypoint alloc] initWithDictionary:[routeAnnotation.points objectAtIndex:idx]];
CLLocation* fromLocation = [fromWaypoint getLocation];
CGPoint fromPoint = [self.routeView.mapView convertCoordinate:fromLocation.coordinate toPointToView:self];
CLLocation* toLocation = [toWaypoint getLocation];
CGPoint toPoint = [self.routeView.mapView convertCoordinate:toLocation.coordinate toPointToView:self];
routeAnnotation.lineColor = [fromWaypoint.weather getTemperatureColor];
CGContextBeginPath(context);
CGContextSetLineWidth(context, 3.0);
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextMoveToPoint(context, fromPoint.x, fromPoint.y);
CGContextAddLineToPoint(context, toPoint.x, toPoint.y);
CGContextStrokePath(context);
CGContextClosePath(context);
CGContextBeginPath(context);
CGContextSetLineWidth(context, 3.0);
CGContextSetStrokeColorWithColor(context, routeAnnotation.lineColor.CGColor);
CGContextMoveToPoint(context, fromPoint.x, fromPoint.y);
CGContextAddLineToPoint(context, toPoint.x, toPoint.y);
CGContextStrokePath(context);
CGContextClosePath(context);
fromWaypoint = toWaypoint;
}
[fromWaypoint release];
[toWaypoint release];
}
}
Aussi, je reçois un
<Error>: CGContextClosePath: no current point.
erreur
, qui je pense est des conneries.
S'il vous plaît allusion à moi! :)