gpt4 book ai didi

iphone - 添加两个MKPolylineView

转载 作者:行者123 更新时间:2023-12-03 20:15:24 24 4
gpt4 key购买 nike

我无法在 MKOverlay View 中添加两个具有不同颜色的不同 MKPolyline View 。关于如何实现这一目标有什么想法吗?谢谢

这是我的代码:

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKOverlayView* overlayView = nil;
UIColor *mycolor;

self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine] autorelease];

mycolor = [UIColor colorWithRed:85.0/255.0 green:133.0/255.0 blue:255.0/255.0 alpha:0.6];
self.routeLineView.fillColor = mycolor;
self.routeLineView.strokeColor = mycolor;
self.routeLineView.lineWidth = 15;
[overlayView addSubview:self.routeLineView];

self.routeLineView2 = [[[MKPolylineView alloc] initWithPolyline:self.routeLine2] autorelease];
mycolor = [UIColor colorWithRed:85.0/255.0 green:19.0/255.0 blue:25.0/255.0 alpha:0.6];
self.routeLineView2.fillColor = mycolor;
self.routeLineView2.strokeColor = mycolor;
self.routeLineView2.lineWidth = 15;
[overlayView addSubview:self.routeLineView2];

return overlayView;
}

最佳答案

对于添加到 map 的每个叠加层,将分别调用 viewForOverlay 方法。因此,在该方法中,您仅返回当前正在调用的覆盖层的覆盖层 View (即 overlay 参数)。

检查它正在请求哪个叠加层的 View ,并仅为该叠加层创建和返回 View 。

例如:

if (overlay == self.routeLine)
{
//create and return overlay view for routeLine...
//set color, etc...
return self.routeLineView;
}
else
if (overlay == self.routeLine2)
{
//create and return overlay view for routeLine2...
//set color, etc...
return self.routeLineView2;
}

return nil;

不要做任何addSubview的事情。只需创建覆盖 View 并返回它即可。

关于iphone - 添加两个MKPolylineView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10865894/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com