【问题标题】:iPhone - Stroking a path does not workiPhone - 抚摸路径不起作用
【发布时间】:2011-07-17 19:18:59
【问题描述】:

我将这些方法放入 MKOverlayView 子类中,但我不明白为什么填充路径有效,以及为什么抚摸同一条路径不起作用...

- (id) init {
    if (!(self = [super init])) return nil;

    self.opaque = NO;  // If not set, just black squares are drawn

    return self;
}

- (void) drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {

    // CGRect rects[2] =  {[self rectForMapRect:mapRect],  [self rectForMapRect:self.country.boundingMapRect]};
    // CGContextClipToRects(context, rects, 2);

    CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
    CGContextSetRGBFillColor(context, 1.0, 0.0, 1.0, 0.9);
    CGContextSetLineWidth(context, 1.0);

    for (MKPolygon* poly in self.polygons) {

        CGPoint origin = [self pointForMapPoint:poly.points[0]];            
        CGContextMoveToPoint(context, origin.x, origin.y);

        for (int i=1; i<poly.pointCount; i++) {
            CGPoint point = [self pointForMapPoint:poly.points[i]];
            CGContextAddLineToPoint(context, point.x, point.y);
        }

        //CGContextFillPath(context);
        CGContextStrokePath(context);
    }
}


-(BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
    return YES;
}

【问题讨论】:

  • 您可以将填充或描边移到循环之外。建立多个子路径(moveto + 线段和曲线段)并同时填充或描边它们是合法的。

标签: iphone core-graphics drawrect cgpath stroke


【解决方案1】:

你的缩小程度如何?您的中风可能正在起作用;它只是没有出现,因为它太薄了。尝试将您的线宽设置为 1.0 / zoomScale(或者,更一般地说,desiredLineWidth * (1.0 / zoomScale))。

(免责声明:我从未真正使用过 MapKit,因此您可能需要按原样使用 zoomScale;根据我对文档的阅读,我会先尝试 1.0 / zoomScale。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-07
    • 1970-01-01
    • 2013-07-06
    • 2019-11-22
    • 2011-09-11
    • 2018-11-13
    相关资源
    最近更新 更多