gpt4 book ai didi

iphone - iOS 7 MKOverlayRenderer 不工作

转载 作者:可可西里 更新时间:2023-11-01 03:52:14 25 4
gpt4 key购买 nike

我正在为 iOS 7 更新一个 iOS 6 应用程序,发现在 iOS 7 中处理覆盖的方式已经完全改变。

我们正在整个 map 上绘制浅灰色叠加层。在 iOS 6 中一切正常,在 iOS 7 中我们没有覆盖。

viewDidLoad 中,我有以下内容:

CLLocationCoordinate2D worldCoords[4] = { {90,-180}, {90,180}, {-90,180}, {-90,-180} };
MKPolygon *worldOverlay = [MKPolygon polygonWithCoordinates:worldCoords
count:4];
[self.mapView addOverlay:worldOverlay];

然后,对于 iOS 6 。 . .

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
if (![overlay isKindOfClass:[MKPolygon class]]) {
return nil;
}
MKPolygon *polygon = (MKPolygon *)overlay;
MKPolygonView *view = [[MKPolygonView alloc] initWithPolygon:polygon];
view.fillColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.4];
return view;
}

适用于 iOS 7。 . .

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
if (![overlay isKindOfClass:[MKPolygon class]]) {
return nil;
}
MKPolygon *polygon = (MKPolygon *)overlay;
MKPolygonRenderer *renderer = [[MKPolygonRenderer alloc] initWithPolygon:polygon];
renderer.fillColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.4];
return renderer;
}

使用断点,我验证了正在调用 mapView:rendererForOverlay: 方法并且它返回的 renderer 对象具有 fillColor 属性正确设置。

关于为什么我们看不到叠加层有什么想法吗?

最佳答案

你所有的代码都是绝对有效的——我把它插入到我的测试 map Controller 中,如果我做一个小的改变它就可以完美地工作:

    CLLocationCoordinate2D worldCoords[4] = { {43,-100}, {43,-80}, {25,-80}, {25,-100} };

所以,问题不在渲染器本身。我相信这与指定第 180 条子午线有关 - Apple 进行了一些更改以支持跨越 iOS7 中第 180 条子午线的区域。我不需要它,因为我只专注于北美,所以我跳过了它,但是有一个 2013 WWDC 视频,他们在其中谈论它 - 请参阅 MapKit session 中的新功能 4:42 左右:https://developer.apple.com/wwdc/videos/

干杯,

关于iphone - iOS 7 MKOverlayRenderer 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18900582/

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