gpt4 book ai didi

iphone - iOS 旋转 MKAnnotationView 以响应 MKMapView 旋转

转载 作者:行者123 更新时间:2023-11-29 04:58:02 30 4
gpt4 key购买 nike

在我的应用程序中,我有一个 MKMapView,其中显示了多个注释。 map 根据设备的航向旋转。要旋转 map ,请执行以下语句(由方法 locationManager 调用:didUpdateHeading:)

self.navigationMapView.mapView.transform = CGAffineTransformMakeRotation(-heading);

其中航向(磁性)以弧度表示。我注意到即使 map 中的注释也会旋转,但我不想要它。我尝试用以下方法修复它:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{

static NSString *identifier = @"AnnotationViewIdentifier";

MKAnnotationView *av = [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

if (av == nil) {
av = [[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];
}
else{
av.annotation = annotation;
}

av.transform = CGAffineTransformMakeRotation(degreesToRadians(self.arController.currentHeading.magneticHeading));

av.canShowCallout = YES;
return av;

}

我想从“didUpdateHeading:”调用这个方法,但我真的不知道该怎么做。 TableView 类具有调用委托(delegate)方法的 reloadData 函数,但这里的情况似乎有所不同。有什么建议么?!

另一个问题,我在 map 上的注释显示了与用户的距离,我想在用户更改位置后立即更新它们(距离标签)。有什么建议吗?!

最佳答案

因此,对于 MKMapView 来说,正确调用它有点烦人。本质上你有两个选择之一。选项 1:在屏幕上创建注释数组并将其从 map_view 中删除,然后将它们重新添加到 map_view 中。本质上是创建您自己的重新加载数据函数。选项 2:做一些简单的事情,例如

CGLocationCoordinate2D coordinate = map_view.center;
map_view.center = coordinate;

-- 本质上,重点是重置 map 的属性,使其重新绘制。然而,这个选项并不总是有效。选项 1 的工作机会较高,但也可能会失败,因此,如果简单地删除注释并重新添加它们不会导致任何情况发生,那么只需取消创建 map ,然后在 map 刷新功能结束时重新创建 map 即可喜欢。

[my_map_view removeFromSuperView];
[my_map_view release];
my_map_view = nil;
my_map_view = [[MKMapView alloc] initWithFrame:CGRectMake(0,0,320,480)];

这些选项之一应该有效。我必须为我的解决方案执行选项一,但我知道有些人很幸运,选项 2 也同样有效。

关于iphone - iOS 旋转 MKAnnotationView 以响应 MKMapView 旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7575546/

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