iPhone - 抚摸路径不起作用

发布于 2024-11-24 18:27:42 字数 1231 浏览 2 评论 0原文

我将这些方法放入 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;
}

I have these methods into a MKOverlayView subclass, and I do not understand why filling a path works, and why stroking that same path doesn't work...

- (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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

定格我的天空 2024-12-01 18:27:42

你的镜头缩小到什么程度?您的中风可能正在发挥作用;它只是不显示出来,因为它太薄了。尝试将线宽设置为1.0/zoomScale(或者更一般地说,desiredLineWidth * (1.0/zoomScale))。

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

How zoomed out are you? It's possible that your stroke is working; it just doesn't show up because it's too thin. Try setting your line width to 1.0 / zoomScale (or, more generally, desiredLineWidth * (1.0 / zoomScale)).

(Disclaimer: I've never actually used MapKit, so you may need to use zoomScale as it is; based on my reading of the documentation, I would try 1.0 / zoomScale first.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文