【发布时间】:2012-10-10 15:30:27
【问题描述】:
我一直在寻找这个问题的根源,但我看不出哪里出了问题。我希望你能在这里帮助我。
我正在尝试在 mapView 中显示注释,图钉被丢弃但无法看到标注,直到我先点击用户位置注释(蓝点),然后返回并点击注释,然后点击注释显示,一切正常。另一种方法是在引脚周围随机敲击,有时在内部敲击,运气好的话,它会显示标注。如果我在地图上放置另一个图钉,我必须执行相同的程序。
这只发生在 iOS6、模拟器和设备中。 iOS5 完美运行。
这是我用于 viewForAnnotation 的代码
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKAnnotationView *annotationView = nil;
//Check if this annotation is not the blue dot for user location
if(annotation != mapView.userLocation) {
//Try to rehuse a previous annotation
annotationView = (MKAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:@"searchResult"];
//If we don't have any, create it
if (annotationView == nil) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"searchResult"];
}
else {//Or re use it
annotationView.annotation = annotation;
}
[annotationView setImage: [UIImage imageNamed:@"customMarker.png"]];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.centerOffset = CGPointMake(0,-16);
annotationView.rightCalloutAccessoryView = nil;//Avoid again the detail button because is a geographic reference
}
else {//Show a text when the blue dot for user location is pressed
[mapView.userLocation setTitle:NSLocalizedString(@"you_are_here", nil)];
}
return annotationView;
}
【问题讨论】:
-
你应该把这个注解去掉View.centerOffset = CGPointMake(0,-16);
-
我之前试过,结果一样。
-
注解的标题是怎么设置的?在 didSelectAnnotationView 中做了什么吗?地图上是否使用了任何手势识别器?
-
@AnnaKarenina 我刚刚删除了手势的所有代码,在 didSelectAnnotationView 我有这个:但仍然没有做任何事情。
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { if([self.map.annotations objectAtIndex:0] != map.userLocation){ id<MKAnnotation> myAnnotation = [self.map.annotations objectAtIndex:0]; [self.map selectAnnotation:myAnnotation animated:YES]; } } -
无法使用显示的代码进行复制。注解的标题是怎么设置的?
标签: iphone ios ios6 mkannotationview ios6-maps