本文介绍了如何在mapview中添加自定义标注视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是objective-c中的mapkit新手。我可以在mapview中添加自定义注释。
I am new to mapkit in objective-c. I am able to add custom annotation in mapview.
我需要放置自定义标注视图,如下图所示
i need to place custom callout view like below image
。
但我没有得到如何设计这样的标注视图。
But i didn't get how can i design callout view like this.
我知道我需要在视图中为注释方法添加标注。
i know i need to add callout in view for annotation method.
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *AnnotationViewID = @"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[mapview dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.image = [UIImage imageNamed:@"blue_without_pin.png"];
annotationView.annotation = annotation;
return annotationView;
}
推荐答案
这方面的一个解决方案是检测相对于父UIView选择的注释的确切坐标,然后直接在MKMapView的顶部绘制UIView。
One solution for this would be to detect the exact coordinate of the annotation selected relative to the parent UIView and then drawing a UIView directly on top of the MKMapView.
这是一个可能有帮助的片段:
Here's a snippet that might help:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
CGPoint pointInMap = [self.mapView convertCoordinate:buildingAnnotation.coordinate
toPointToView:self.view];
// Hide the default callout generated by MKMapView
[mapView deselectAnnotation:view.annotation animated:NO];
// Create a custom callout view and center the arrow on the pointInMap CGPoint
}
这篇关于如何在mapview中添加自定义标注视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!