Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iphonequartz在两条线的上面画两条线会产生蠕虫效应_Iphone_Drawing_Line_Quartz 2d_Routes - Fatal编程技术网

iphonequartz在两条线的上面画两条线会产生蠕虫效应

iphonequartz在两条线的上面画两条线会产生蠕虫效应,iphone,drawing,line,quartz-2d,routes,Iphone,Drawing,Line,Quartz 2d,Routes,我正在使用Quartz-2D for iPhone在地图上显示路线。这条路线是根据温度而上色的。因为有些街道是黄色的,所以我在路线线下使用了一条稍粗的黑色线来创建边界效果,这样路线的黄色部分就可以在黄色的街道上看到。但是,即使黑线和路线一样粗,整个路线看起来就像一条蠕虫(非常难看)。我认为这是因为我在各个航路点之间画线,而不是使用最后一个航路点作为下一个起始航路点。这样,如果缺少几个航路点,路线仍将没有切入点 要显示这两行而不产生蠕虫效果,我需要做什么 -(void) drawRect:(CGR

我正在使用Quartz-2D for iPhone在地图上显示路线。这条路线是根据温度而上色的。因为有些街道是黄色的,所以我在路线线下使用了一条稍粗的黑色线来创建边界效果,这样路线的黄色部分就可以在黄色的街道上看到。但是,即使黑线和路线一样粗,整个路线看起来就像一条蠕虫(非常难看)。我认为这是因为我在各个航路点之间画线,而不是使用最后一个航路点作为下一个起始航路点。这样,如果缺少几个航路点,路线仍将没有切入点

要显示这两行而不产生蠕虫效果,我需要做什么

-(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];       
}
}
-(void)drawRect:(CGRect)rect
{
CSRouteAnotation*RouteAnotation=(CSRouteAnotation*)self.routeView.annotation;
//只有在我们不处于过渡模式的情况下才能画出我们的线
//阿库塔利有几点要画。
如果(!self.hidden&&nil!=routeAnotation.points&&routeAnotation.points.count>0)
{
CGContextRef context=UIGraphicsGetCurrentContext();
航路点*fromWaypoint=[[Waypoint alloc]initWithDictionary:[RouteAnotation.points objectAtIndex:0]];
航路点*拖航点;
对于(int idx=1;idx
还有,我有一个

<Error>: CGContextClosePath: no current point.
:CGContextClosePath:没有当前点。
错误,我认为这是胡说八道

请提示我!:)



听起来可能与线帽有关。试着用平头帽画画,看看有什么帮助

更新: 我知道现在发生了什么。它只是一条“背景”线,与前一条“背景”+“放弃”线所覆盖的像素重叠。更改为绘制所有“背景”线,然后绘制所有“前景”线可以避免此问题。 你的线条仍然会透支一些像素,但只有相同的颜色,所以你不会注意到。
(请注意,大多数线条端点封口样式都延伸到线条中实际点的周围,使效果更加明显-重叠像素更多。)

您可以只绘制一条线条并使用它,而不是绘制两条线条吗?

谢谢大家!因此,简单地添加阴影或线帽没有帮助,效果保持不变。然而,我只是玩了一下代码,结果是,如果我在完整路径中分别画两条线(在两个for循环中),效果就消失了!然后我在背景线上加上了方形线帽,使它稍微好看一点

现在我唯一想知道的是…这有什么解释?这是新代码,我以后会优化它

-(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.5);
        CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
        CGContextSetLineCap(context, kCGLineCapSquare);
        CGContextMoveToPoint(context, fromPoint.x, fromPoint.y);
        CGContextAddLineToPoint(context, toPoint.x, toPoint.y);
        CGContextStrokePath(context);
        CGContextClosePath(context);

        fromWaypoint = toWaypoint;

    }

    // zweite for schleife
    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, routeAnnotation.lineColor.CGColor);
        CGContextSetLineCap(context, kCGLineCapSquare );
        CGContextMoveToPoint(context, fromPoint.x, fromPoint.y);
        CGContextAddLineToPoint(context, toPoint.x, toPoint.y);
        CGContextStrokePath(context);
        CGContextClosePath(context);

    }

    [fromWaypoint release];
   }
}       
-(void)drawRect:(CGRect)rect{
CSRouteAnotation*RouteAnotation=(CSRouteAnotation*)self.routeView.annotation;
//只有在我们不处于过渡模式的情况下才能画出我们的线
//阿库塔利有几点要画。
如果(!self.hidden&&nil!=routeAnotation.points&&routeAnotation.points.count>0)
{
CGContextRef context=UIGraphicsGetCurrentContext();
航路点*fromWaypoint=[[Waypoint alloc]initWithDictionary:[RouteAnotation.points objectAtIndex:0]];
航路点*拖航点;
对于(int idx=1;idx