iPhone - 抚摸路径不起作用
我将这些方法放入 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技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的镜头缩小到什么程度?您的中风可能正在发挥作用;它只是不显示出来,因为它太薄了。尝试将线宽设置为
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 try1.0 / zoomScale
first.)